Fixes #1933. Fixed JSON encoding of input data, and added more optgroup controls on JS-side

This commit is contained in:
Timothy Mastny
2018-06-18 19:58:50 -05:00
parent 572c863bff
commit 165ce26b2f
2 changed files with 45 additions and 4 deletions

View File

@@ -67,9 +67,11 @@ $.extend(selectInputBinding, {
if (data.hasOwnProperty('url')) {
selectize = this._selectize(el);
selectize.clearOptions();
selectize.clearOptionGroups();
var thiz = this, loaded = false;
selectize.settings.load = function(query, callback) {
var settings = selectize.settings;
var thiz2 = this;
$.ajax({
url: data.url,
data: {
@@ -84,6 +86,10 @@ $.extend(selectInputBinding, {
callback();
},
success: function(res) {
$.each(res, function(index, elem) {
thiz2.addOptionGroup(elem['group'], { group: elem['group'] });
});
thiz2.refreshOptions();
callback(res);
if (!loaded && data.hasOwnProperty('value'))
thiz.setValue(el, data.value);
@@ -123,7 +129,10 @@ $.extend(selectInputBinding, {
var options = $.extend({
labelField: 'label',
valueField: 'value',
searchField: ['label']
searchField: ['label'],
optgroupField: 'group',
optgroupLabelField: 'group',
ptgroupValueField: 'group'
}, JSON.parse(config.html()));
// selectize created from selectInput()
if (typeof(config.data('nonempty')) !== 'undefined') {