-
Notifications
You must be signed in to change notification settings - Fork 684
Description
A "resync" method would be helpful.
This would simply resynchronize the selected state between the native select and the widget.
This would be useful since it would allow changing selected states of the native select's options and then this could be reflected on the widget by simply calling the resync method.
Currently, the only way to show this update in the widget is by calling refresh, which rebuilds all the options from scratch which is really overkill if you are just changing selected states as in this case. Sometimes I think "refresh" should really be called "rebuild" since it is really rebuilding the menu.
Another thing a resync method would make possible would be a val(x) (set value) method for the widget. This would just call $('select').val(x) on the native select, then call the resync() method to reflect the new selections in the widget.
/**
* Updates the widget checkboxes' checked states
* from the native select options' selected states.
*
*/
resync : function() {
var $inputs = this.$inputs;
var $options = this.element.find('option');
if ($inputs.length === $options.length) {
var inputValues = {};
$inputs.each( function() {
inputValues[this.value] = this;
});
$options.each( function() {
if (this.value in inputValues) {
inputValues[this.value].checked = this.selected;
}
});
this._trigger('resync');
this.update();
}
else {
this.refresh();
}
},