From 640bd059c8bf26072bfb814929b3d634913a9a78 Mon Sep 17 00:00:00 2001 From: Bill Keese Date: Thu, 27 Aug 2015 15:32:31 +0900 Subject: [PATCH] Leverage delite/FormWidget#afterFormResetCallback(). Refs ibm-js/delite#423, #584. The form reset code for ComboBox, Select, Slider, and Toggle was apparently added but never tested. It's unclear if it worked before or after this change. The original commits for the form reset handling were: * Combobox: 59e59c0906670794fc88111ff58aed34544410f6 * Select: e80ca84bc2ba1390486a83c4704b584b6e15aeee * Slider: c8cf2f03cc90aa109e405c9b67aee6653e8786d8 * Toggle: 6ccd37040aafef9a45330554f510f2e4a556e380 --- Combobox.js | 28 +++++++++++----------------- Select.js | 26 ++++++++++---------------- Slider.js | 11 ----------- Toggle.js | 13 +++++-------- 4 files changed, 26 insertions(+), 52 deletions(-) diff --git a/Combobox.js b/Combobox.js index 78099a8b56..d43ba6dbdb 100644 --- a/Combobox.js +++ b/Combobox.js @@ -297,24 +297,18 @@ define([ .on("selectstart", false); } }, - - attachedCallback: function () { - // If the widget is in a form, reset the initial value of the widget - // when the form is reset - if (this.valueNode.form) { - this.on("reset", function () { - this.defer(function () { - if (this.value !== this.valueNode.value || - // In multiple mode, with no option selected before reset, - // valueNode.value is the same but still needs the reinit to get - // the correct initial inputNode.value. - this.selectionMode === "multiple") { - this._initValue(); - } - }); - }.bind(this), this.valueNode.form); + + afterFormResetCallback: function () { + if (this.value !== this.valueNode.value || + // In multiple mode, with no option selected before reset, + // valueNode.value is the same but still needs the reinit to get + // the correct initial inputNode.value. + this.selectionMode === "multiple") { + this._initValue(); } - + }, + + attachedCallback: function () { // Declarative case (list specified declaratively inside the declarative Combobox) if (this.list === this._defaultList) { var list = this.querySelector("d-list"); diff --git a/Select.js b/Select.js index a82894d78e..7c35bd9f4b 100644 --- a/Select.js +++ b/Select.js @@ -134,23 +134,17 @@ define([ // of selectionMode as provided by delite/Selection. template: template, - - attachedCallback: function () { - // If the widget is in a form, reset the initial value of the widget - // when the form is reset - if (this.valueNode.form) { - this.on("reset", function () { - this.defer(function () { - this.valueNode.selectedIndex = - this.selectionMode === "single" ? - // First option selected in "single" selection mode, and - // no option selected in "multiple" mode - 0 : -1; - this.value = this.valueNode.value; - }); - }.bind(this), this.valueNode.form); - } + afterFormResetCallback: function () { + this.valueNode.selectedIndex = + this.selectionMode === "single" ? + // First option selected in "single" selection mode, and + // no option selected in "multiple" mode + 0 : -1; + this.value = this.valueNode.value; + }, + + attachedCallback: function () { // To provide graphic feedback for focus, react to focus/blur events // on the underlying native select. The CSS class is used instead // of the focus pseudo-class because the browsers give the focus diff --git a/Slider.js b/Slider.js index 1e5b21efa3..f82d671f4a 100644 --- a/Slider.js +++ b/Slider.js @@ -332,17 +332,6 @@ define([ }, attachedCallback: function () { - // if the form is reset, then notify the widget to reposition the handles - if (this.valueNode.form) { - var self = this; - this.on("reset", function () { - self.defer(function () { - if (this.value !== this.valueNode.value) { - this.value = this.valueNode.value; - } - }); - }, this.valueNode.form); - } // Chrome: avoids text selection of elements when mouse is dragged outside of the Slider. this.onmousedown = function (e) { e.preventDefault(); diff --git a/Toggle.js b/Toggle.js index ce8ecb6df7..f3118a7beb 100644 --- a/Toggle.js +++ b/Toggle.js @@ -28,14 +28,11 @@ define([ value: "on", attachedCallback: function () { - var initState = this.checked; - if (this.valueNode && this.valueNode.form) { - this.on("reset", function () { - this.defer(function () { - this.checked = initState; - }); - }.bind(this), this.valueNode.form); - } + this._initState = this.checked; + }, + + afterFormResetCallback: function () { + this.checked = this._initState; }, postRender: function () {