Skip to content

Commit

Permalink
Update selectInput's binding to use selectize.js' getValue() method…
Browse files Browse the repository at this point in the history
… when relevant (#3926)

Co-authored-by: cpsievert <cpsievert@users.noreply.github.com>
  • Loading branch information
cpsievert and cpsievert authored Oct 26, 2023
1 parent a1b9fda commit 77bc4e9
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 14 deletions.
7 changes: 6 additions & 1 deletion inst/www/shared/shiny.js
Original file line number Diff line number Diff line change
Expand Up @@ -8818,7 +8818,12 @@
}, {
key: "getValue",
value: function getValue(el) {
return (0, import_jquery15.default)(el).val();
if (!isSelectize(el)) {
return (0, import_jquery15.default)(el).val();
} else {
var selectize = this._selectize(el);
return selectize === null || selectize === void 0 ? void 0 : selectize.getValue();
}
}
}, {
key: "setValue",
Expand Down
4 changes: 2 additions & 2 deletions inst/www/shared/shiny.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion inst/www/shared/shiny.min.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions inst/www/shared/shiny.min.js.map

Large diffs are not rendered by default.

13 changes: 8 additions & 5 deletions srcts/src/bindings/input/selectInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import $ from "jquery";
import { InputBinding } from "./inputBinding";
import { $escape, hasDefinedProperty, updateLabel } from "../../utils";
import { indirectEval } from "../../utils/eval";
import type { NotUndefined } from "../../utils/extraTypes";

type SelectHTMLElement = HTMLSelectElement & { nonempty: boolean };

Expand Down Expand Up @@ -61,10 +60,14 @@ class SelectInputBinding extends InputBinding {
getId(el: SelectHTMLElement): string {
return InputBinding.prototype.getId.call(this, el) || el.name;
}
getValue(
el: HTMLElement
): NotUndefined<ReturnType<JQuery<HTMLElement>["val"]>> {
return $(el).val() as NotUndefined<ReturnType<JQuery<HTMLElement>["val"]>>;
getValue(el: SelectHTMLElement): any {
if (!isSelectize(el)) {
return $(el).val();
} else {
const selectize = this._selectize(el);

return selectize?.getValue();
}
}
setValue(el: SelectHTMLElement, value: string): void {
if (!isSelectize(el)) {
Expand Down
3 changes: 1 addition & 2 deletions srcts/types/src/bindings/input/selectInput.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/// <reference types="selectize" />
import { InputBinding } from "./inputBinding";
import type { NotUndefined } from "../../utils/extraTypes";
type SelectHTMLElement = HTMLSelectElement & {
nonempty: boolean;
};
Expand All @@ -19,7 +18,7 @@ declare class SelectInputBinding extends InputBinding {
find(scope: HTMLElement): JQuery<HTMLElement>;
getType(el: HTMLElement): string | null;
getId(el: SelectHTMLElement): string;
getValue(el: HTMLElement): NotUndefined<ReturnType<JQuery<HTMLElement>["val"]>>;
getValue(el: SelectHTMLElement): any;
setValue(el: SelectHTMLElement, value: string): void;
getState(el: SelectHTMLElement): {
label: JQuery<HTMLElement>;
Expand Down

0 comments on commit 77bc4e9

Please sign in to comment.