From 6e89095822dc9be86a30b906caddc6bb77bb8598 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20S=CC=8Cirka?= Date: Wed, 21 Feb 2024 13:46:52 +0100 Subject: [PATCH] Fixed Form and DataTransformer. --- components/datatransformer/render.html | 5 ++--- components/form/render.html | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/components/datatransformer/render.html b/components/datatransformer/render.html index 38805f0..95681da 100644 --- a/components/datatransformer/render.html +++ b/components/datatransformer/render.html @@ -4,15 +4,14 @@ exports.make = function(instance, config) { instance.state.notify = true; + instance.state.bind = true; instance.on('ready', function() { - var fn = config.value ? new Function('value', config.value) : null; - instance.on('notify', function(value) { if (fn) { var val = fn(value); if (val != undefined) - instance.set('value', val); + instance.set('value', val, 'nobind'); } }); diff --git a/components/form/render.html b/components/form/render.html index 455f29c..142d8bc 100644 --- a/components/form/render.html +++ b/components/form/render.html @@ -123,6 +123,7 @@ var invalid = false; var modified = false; + var model = {}; for (var m of children) { @@ -135,11 +136,24 @@ if (m.validate && !m.validate()) invalid = true; + if (m.state.bind && m.config.path && m.config.path.charAt(0) !== '@') + instance.write(model, m.config.path, m.state.value); + } button && button.prop('disabled', !modified || invalid); instance.set('invalid', invalid); instance.set('modified', modified); + + var tmp = instance.state.value || {}; + + if (!tmp) + tmp = {}; + + for (var key in model) + tmp[key] = model[key]; + + instance.set('value', tmp); }; instance.on('state', function(e) {