Skip to content

Commit b6bcfc8

Browse files
dvg-p4gadenbuie
andauthored
Work around a selectize bug (re-fixes #3966) (#4142)
* Work around a selectize bug (re-fixes #3966) --------- Co-authored-by: Garrick Aden-Buie <garrick@adenbuie.com>
1 parent d37beee commit b6bcfc8

File tree

6 files changed

+14
-14
lines changed

6 files changed

+14
-14
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
* Fixed a bug with stack trace capturing that caused reactives with very long async promise chains (hundreds/thousands of steps) to become extremely slow. Chains this long are unlikely to be written by hand, but {coro} async generators and {elmer} async streaming were easily creating problematically long chains. (#4155)
2424

25+
* Updating the choices of a `selectizeInput()` via `updateSelectizeInput()` with `server = TRUE` no longer retains the selected choice as a deselected option if the current value is not part of the new choices. (@dvg-p4 #4142)
26+
2527
# shiny 1.9.1
2628

2729
## Bug fixes

inst/www/shared/shiny.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10662,10 +10662,8 @@
1066210662
}
1066310663
if (hasDefinedProperty(data, "url")) {
1066410664
var _selectize2 = this._selectize(el);
10665+
_selectize2.clear();
1066510666
_selectize2.clearOptions();
10666-
if (hasDefinedProperty(data, "value")) {
10667-
_selectize2.clear();
10668-
}
1066910667
var loaded = false;
1067010668
_selectize2.settings.load = function(query, callback) {
1067110669
var settings = _selectize2.settings;

inst/www/shared/shiny.js.map

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/www/shared/shiny.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inst/www/shared/shiny.min.js.map

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

srcts/src/bindings/input/selectInput.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,13 @@ class SelectInputBinding extends InputBinding {
142142
};
143143
};
144144

145+
// Calling selectize.clear() first works around https://github.com/selectize/selectize.js/issues/2146
146+
// As of selectize.js >= v0.13.1, .clearOptions() clears the selection,
147+
// but does NOT remove the previously-selected options. So unless we call
148+
// .clear() first, the current selection(s) will remain as (deselected)
149+
// options. See #3966 #4142
150+
selectize.clear();
145151
selectize.clearOptions();
146-
// If a new `selected` value is provided, also clear the current selection (otherwise it gets added as an option).
147-
// Note: although the selectize docs suggest otherwise, as of selectize.js >v0.15.2,
148-
// .clearOptions() no longer implicitly .clear()s (see #3967)
149-
if (hasDefinedProperty(data, "value")) {
150-
selectize.clear();
151-
}
152152
let loaded = false;
153153

154154
selectize.settings.load = function (query: string, callback: CallbackFn) {

0 commit comments

Comments
 (0)