Skip to content

Commit

Permalink
Use new selectize suffix. Fixes #2245
Browse files Browse the repository at this point in the history
  • Loading branch information
wch committed Nov 6, 2018
1 parent 5e2b40d commit 83b6dff
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions srcjs/input_binding_select.js
Expand Up @@ -22,10 +22,14 @@ $.extend(selectInputBinding, {
return $(el).val();
},
setValue: function(el, value) {
var selectize = this._selectize(el);
if (typeof(selectize) !== 'undefined') {
selectize.setValue(value);
} else $(el).val(value);
if (this._is_selectize(el)) {
$(el).val(value);
} else {
let selectize = this._selectize(el);
if (selectize) {
selectize.setValue(value);
}
}
},
getState: function(el) {
// Store options in an array of objects, each with with value and label
Expand Down Expand Up @@ -119,8 +123,15 @@ $.extend(selectInputBinding, {
this.setValue(el, data.value);
}

if (data.hasOwnProperty('label'))
$(el).parent().parent().find('label[for="' + $escape(el.id) + '"]').text(data.label);
if (data.hasOwnProperty('label')) {
let label_name = $escape(el.id);
if (this._is_selectize(el)) {
label_name += "-selectized";
}
$(el).parent().parent()
.find('label[for="' + label_name + '"]')
.text(data.label);
}

$(el).trigger('change');
},
Expand All @@ -141,6 +152,15 @@ $.extend(selectInputBinding, {
initialize: function(el) {
this._selectize(el);
},
// Return true if it's a selectize input, false if it's a regular select input.
_is_selectize: function(el) {
var config = $(el).parent().find('script[data-for="' + $escape(el.id) + '"]');
if (config.length === 0) {
return false;
} else {
return true;
}
},
_selectize: function(el, update) {
if (!$.fn.selectize) return undefined;
var $el = $(el);
Expand Down

0 comments on commit 83b6dff

Please sign in to comment.