Skip to content

Commit 77bc4e9

Browse files
authored
Update selectInput's binding to use selectize.js' getValue() method when relevant (#3926)
Co-authored-by: cpsievert <[email protected]>
1 parent a1b9fda commit 77bc4e9

File tree

6 files changed

+21
-14
lines changed

6 files changed

+21
-14
lines changed

inst/www/shared/shiny.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8818,7 +8818,12 @@
88188818
}, {
88198819
key: "getValue",
88208820
value: function getValue(el) {
8821-
return (0, import_jquery15.default)(el).val();
8821+
if (!isSelectize(el)) {
8822+
return (0, import_jquery15.default)(el).val();
8823+
} else {
8824+
var selectize = this._selectize(el);
8825+
return selectize === null || selectize === void 0 ? void 0 : selectize.getValue();
8826+
}
88228827
}
88238828
}, {
88248829
key: "setValue",

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: 3 additions & 3 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: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import $ from "jquery";
22
import { InputBinding } from "./inputBinding";
33
import { $escape, hasDefinedProperty, updateLabel } from "../../utils";
44
import { indirectEval } from "../../utils/eval";
5-
import type { NotUndefined } from "../../utils/extraTypes";
65

76
type SelectHTMLElement = HTMLSelectElement & { nonempty: boolean };
87

@@ -61,10 +60,14 @@ class SelectInputBinding extends InputBinding {
6160
getId(el: SelectHTMLElement): string {
6261
return InputBinding.prototype.getId.call(this, el) || el.name;
6362
}
64-
getValue(
65-
el: HTMLElement
66-
): NotUndefined<ReturnType<JQuery<HTMLElement>["val"]>> {
67-
return $(el).val() as NotUndefined<ReturnType<JQuery<HTMLElement>["val"]>>;
63+
getValue(el: SelectHTMLElement): any {
64+
if (!isSelectize(el)) {
65+
return $(el).val();
66+
} else {
67+
const selectize = this._selectize(el);
68+
69+
return selectize?.getValue();
70+
}
6871
}
6972
setValue(el: SelectHTMLElement, value: string): void {
7073
if (!isSelectize(el)) {

srcts/types/src/bindings/input/selectInput.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/// <reference types="selectize" />
22
import { InputBinding } from "./inputBinding";
3-
import type { NotUndefined } from "../../utils/extraTypes";
43
type SelectHTMLElement = HTMLSelectElement & {
54
nonempty: boolean;
65
};
@@ -19,7 +18,7 @@ declare class SelectInputBinding extends InputBinding {
1918
find(scope: HTMLElement): JQuery<HTMLElement>;
2019
getType(el: HTMLElement): string | null;
2120
getId(el: SelectHTMLElement): string;
22-
getValue(el: HTMLElement): NotUndefined<ReturnType<JQuery<HTMLElement>["val"]>>;
21+
getValue(el: SelectHTMLElement): any;
2322
setValue(el: SelectHTMLElement, value: string): void;
2423
getState(el: SelectHTMLElement): {
2524
label: JQuery<HTMLElement>;

0 commit comments

Comments
 (0)