Update to latest FormSaver, triggering change events when form fields are updated

This commit is contained in:
Anna Sidwell 2018-04-16 09:33:53 +10:00
parent 67fa6c6b74
commit e067443756

View File

@ -69,6 +69,11 @@ var FormSaver = function () {
return tag; return tag;
} }
} }
}, {
key: "triggerChangeEvent",
value: function triggerChangeEvent(element) {
element.dispatchEvent(new Event('change'));
}
}, { }, {
key: "deserialise", key: "deserialise",
value: function deserialise(data) { value: function deserialise(data) {
@ -123,6 +128,8 @@ var FormSaver = function () {
} else { } else {
element.value = field.value; element.value = field.value;
} }
this.triggerChangeEvent(element);
} else { } else {
// We've got a list. This means we're radio or checkbox. // We've got a list. This means we're radio or checkbox.
// Go over all the elements and select the right ones // Go over all the elements and select the right ones
@ -134,7 +141,11 @@ var FormSaver = function () {
for (var _iterator3 = element[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { for (var _iterator3 = element[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
var input = _step3.value; var input = _step3.value;
var oldVal = input.checked;
input.checked = field.value.includes(input.value); input.checked = field.value.includes(input.value);
if (oldVal !== input.checked) {
this.triggerChangeEvent(input);
}
} }
} catch (err) { } catch (err) {
_didIteratorError3 = true; _didIteratorError3 = true;