diff --git a/FormWidget.js b/FormWidget.js index ed531ebfb3..d5f142c7e3 100644 --- a/FormWidget.js +++ b/FormWidget.js @@ -98,6 +98,28 @@ define([ * @default undefined */ + _mapAttributes: dcl.superCall(function (sup) { + return function () { + var input = this.querySelector("input"); + if (input) { + // Get value and name from embedded node. + if (input.value) { + this.setAttribute("value", input.value); + } + if (input.name) { + this.setAttribute("name", input.name); + } + } else { + // Create this.valueNode as a convenience, but don't add to the DOM because that breaks widgets like + // deliteful/Checkbox that unconditionally create their own this.valueNode: + // You end up with two embedded nodes. + input = this.ownerDocument.createElement("input"); + } + this.valueNode = input; + return sup.call(this); + }; + }), + refreshRendering: function (oldValues) { // Handle disabled and tabIndex, across the tabStops and root node. // No special processing is needed for tabStops other than just to refresh disabled and tabIndex. diff --git a/tests/functional/FormValueWidget.html b/tests/functional/FormValueWidget.html index 8e6db6997f..54a6ec9107 100644 --- a/tests/functional/FormValueWidget.html +++ b/tests/functional/FormValueWidget.html @@ -42,19 +42,9 @@ "{{this.value}}" + " " + " " + - "" + + "" + // for this.valueNode "" ), - postRender: function () { - // TODO: move this logic into FormValueWidget itself? - this.valueNode = this.containerNode.querySelector("input"); - if (this.valueNode) { - this.value = this.valueNode.value; - } else { - this.valueNode = this.ownerDocument.createElement("input"); - this.containerNode.appendChild(this.valueNode); - } - }, decrement: function () { this.value--; }, @@ -72,7 +62,7 @@