Skip to content

Commit

Permalink
Leverage delite/FormWidget#afterFormResetCallback().
Browse files Browse the repository at this point in the history
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: 59e59c0
* Select: e80ca84
* Slider: c8cf2f0
* Toggle: 6ccd370
  • Loading branch information
wkeese committed Aug 28, 2015
1 parent 7258732 commit 640bd05
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 52 deletions.
28 changes: 11 additions & 17 deletions Combobox.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
26 changes: 10 additions & 16 deletions Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 0 additions & 11 deletions Slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
13 changes: 5 additions & 8 deletions Toggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit 640bd05

Please sign in to comment.