Fix selectize bug where value is set merely on query results (#2193)

This bug is new since v1.1. When results are returned from selectize's
server-side endpoint, iff no results have been selected before, then
the control should be set to either its specified initial value (the
one specified in selectInput/selectizeInput) or, if none was provided
AND the selectize control is multiple=FALSE, then select the first
entry automatically.

That's the desired behavior; the bug was that last part, "select the
first entry automatically", was happening whether results had already
been selected before or not. This was causing merely typing in the
control to cause the value to be changed.

Fixes #2191
This commit is contained in:
Joe Cheng
2018-09-25 12:21:16 -07:00
committed by GitHub
parent 85bed0582a
commit e7c4656e8f
5 changed files with 17 additions and 13 deletions

View File

@@ -5353,11 +5353,13 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
selectize.addOptionGroup(elem.group, { group: elem.group });
});
callback(res);
if (!loaded && data.hasOwnProperty('value')) {
selectize.setValue(data.value);
} else if (settings.maxItems === 1) {
// first item selected by default only for single-select
selectize.setValue(res[0].value);
if (!loaded) {
if (data.hasOwnProperty('value')) {
selectize.setValue(data.value);
} else if (settings.maxItems === 1) {
// first item selected by default only for single-select
selectize.setValue(res[0].value);
}
}
loaded = true;
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -91,11 +91,13 @@ $.extend(selectInputBinding, {
selectize.addOptionGroup(elem.group, { group: elem.group });
});
callback(res);
if (!loaded && data.hasOwnProperty('value')) {
selectize.setValue(data.value);
} else if (settings.maxItems === 1) {
// first item selected by default only for single-select
selectize.setValue(res[0].value);
if (!loaded) {
if (data.hasOwnProperty('value')) {
selectize.setValue(data.value);
} else if (settings.maxItems === 1) {
// first item selected by default only for single-select
selectize.setValue(res[0].value);
}
}
loaded = true;
}