mirror of
https://github.com/rstudio/shiny.git
synced 2026-01-09 15:08:04 -05:00
Prevent .selectize() updates from destroying .data() and event listeners (#3923)
Co-authored-by: cpsievert <cpsievert@users.noreply.github.com>
This commit is contained in:
@@ -1064,14 +1064,8 @@ $.extend(Selectize.prototype, {
|
||||
self.ignoreHover = self.settings.ignoreHover;
|
||||
});
|
||||
|
||||
var inputPlaceholder = $('<div></div>');
|
||||
var inputChildren = $input.children().detach();
|
||||
|
||||
$input.replaceWith(inputPlaceholder);
|
||||
inputPlaceholder.replaceWith($input);
|
||||
|
||||
this.revertSettings = {
|
||||
$children : inputChildren,
|
||||
$children : $input.children().detach(),
|
||||
tabindex : $input.attr('tabindex')
|
||||
};
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
2
inst/www/shared/shiny.min.js
vendored
2
inst/www/shared/shiny.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -2,7 +2,6 @@ import $ from "jquery";
|
||||
import { InputBinding } from "./inputBinding";
|
||||
import { $escape, hasDefinedProperty, updateLabel } from "../../utils";
|
||||
import { indirectEval } from "../../utils/eval";
|
||||
import { shinyBindAll, shinyUnbindAll } from "../../shiny/initedMethods";
|
||||
import type { NotUndefined } from "../../utils/extraTypes";
|
||||
|
||||
type SelectHTMLElement = HTMLSelectElement & { nonempty: boolean };
|
||||
@@ -285,35 +284,18 @@ class SelectInputBinding extends InputBinding {
|
||||
// @ts-expect-error; Need to type `options` keys to know exactly which values are accessed.
|
||||
options[x] = indirectEval("(" + options[x] + ")");
|
||||
});
|
||||
|
||||
let control = this._newSelectize($el, options);
|
||||
|
||||
let control = $el.selectize(options)[0].selectize as SelectizeInfo;
|
||||
// .selectize() does not really update settings; must destroy and rebuild
|
||||
|
||||
if (update) {
|
||||
const settings = $.extend(control.settings, options);
|
||||
|
||||
control.destroy();
|
||||
control = this._newSelectize($el, settings);
|
||||
control = $el.selectize(settings)[0].selectize as SelectizeInfo;
|
||||
}
|
||||
|
||||
return control;
|
||||
}
|
||||
|
||||
protected _newSelectize(
|
||||
$el: JQuery<HTMLSelectElement>,
|
||||
options: SelectizeOptions
|
||||
): SelectizeInfo {
|
||||
// Starting with selectize v0.15.2, $el.selectize() can prune the <select>
|
||||
// element from the DOM, meaning that if we're already bound to it, we'll
|
||||
// lose the binding. So if we are bound, unbind first, then rebind after.
|
||||
// (Note this is quite similar to how Shiny.renderContent() works.)
|
||||
const binding = $el.data("shiny-input-binding");
|
||||
if (binding) shinyUnbindAll($el.parent());
|
||||
const control = $el.selectize(options)[0].selectize as SelectizeInfo;
|
||||
/* eslint-disable @typescript-eslint/no-floating-promises */
|
||||
if (binding) shinyBindAll($el.parent());
|
||||
return control;
|
||||
}
|
||||
}
|
||||
|
||||
export { SelectInputBinding };
|
||||
|
||||
@@ -34,7 +34,6 @@ declare class SelectInputBinding extends InputBinding {
|
||||
unsubscribe(el: HTMLElement): void;
|
||||
initialize(el: SelectHTMLElement): void;
|
||||
protected _selectize(el: SelectHTMLElement, update?: boolean): SelectizeInfo | undefined;
|
||||
protected _newSelectize($el: JQuery<HTMLSelectElement>, options: SelectizeOptions): SelectizeInfo;
|
||||
}
|
||||
export { SelectInputBinding };
|
||||
export type { SelectInputReceiveMessageData };
|
||||
|
||||
32
tools/selectize-patches/008-selectize-revert-d2564a0a.patch
Normal file
32
tools/selectize-patches/008-selectize-revert-d2564a0a.patch
Normal file
@@ -0,0 +1,32 @@
|
||||
diff --git a/inst/www/shared/selectize/js/selectize.js b/inst/www/shared/selectize/js/selectize.js
|
||||
index 767f45e1c..a902fae5b 100644
|
||||
--- a/inst/www/shared/selectize/js/selectize.js
|
||||
+++ b/inst/www/shared/selectize/js/selectize.js
|
||||
@@ -1064,14 +1064,8 @@ $.extend(Selectize.prototype, {
|
||||
self.ignoreHover = self.settings.ignoreHover;
|
||||
});
|
||||
|
||||
- var inputPlaceholder = $('<div></div>');
|
||||
- var inputChildren = $input.children().detach();
|
||||
-
|
||||
- $input.replaceWith(inputPlaceholder);
|
||||
- inputPlaceholder.replaceWith($input);
|
||||
-
|
||||
this.revertSettings = {
|
||||
- $children : inputChildren,
|
||||
+ $children : $input.children().detach(),
|
||||
tabindex : $input.attr('tabindex')
|
||||
};
|
||||
|
||||
diff --git a/inst/www/shared/shiny.js b/inst/www/shared/shiny.js
|
||||
index aeff68aa3..db9880f26 100644
|
||||
Binary files a/inst/www/shared/shiny.js and b/inst/www/shared/shiny.js differ
|
||||
diff --git a/inst/www/shared/shiny.js.map b/inst/www/shared/shiny.js.map
|
||||
index 34350b024..1abf54644 100644
|
||||
Binary files a/inst/www/shared/shiny.js.map and b/inst/www/shared/shiny.js.map differ
|
||||
diff --git a/inst/www/shared/shiny.min.js b/inst/www/shared/shiny.min.js
|
||||
index 8b8027fd3..eb1994aac 100644
|
||||
Binary files a/inst/www/shared/shiny.min.js and b/inst/www/shared/shiny.min.js differ
|
||||
diff --git a/inst/www/shared/shiny.min.js.map b/inst/www/shared/shiny.min.js.map
|
||||
index 560e1492e..0de12987b 100644
|
||||
Binary files a/inst/www/shared/shiny.min.js.map and b/inst/www/shared/shiny.min.js.map differ
|
||||
Reference in New Issue
Block a user