Skip to content

Commit

Permalink
Fix sporadic dates (#3664) (#3665)
Browse files Browse the repository at this point in the history
* Remove dateInput and dateRangeInput handlers for keyup and input events

This prevents spurious updates while typing, but still sends when enter is pressed, focus is lost, or the GUI is clicked (due to the remaining `changeDate` and `change` handlers).

* chore: small edits to comments and NEWS item

---------

Co-authored-by: Garrick Aden-Buie <[email protected]>
  • Loading branch information
dvg-p4 and gadenbuie authored Sep 30, 2024
1 parent 2e2114f commit abf7138
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 33 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

* Fixed a bug with `sliderInput()` when used as a range slider that made it impossible to change the slider value when both handles were at the maximum value. (#4131)

* `dateInput` and `dateRangeInput` no longer send immediate updates to the server when the user is typing a date input. Instead, it waits until the user presses Enter or clicks out of the field to send the update, avoiding spurious and incorrect date values. Note that an update is still sent immediately when the field is cleared. (#3664)

# shiny 1.9.1

## Bug fixes
Expand Down
12 changes: 0 additions & 12 deletions inst/www/shared/shiny.js
Original file line number Diff line number Diff line change
Expand Up @@ -8061,12 +8061,6 @@
}, {
key: "subscribe",
value: function subscribe(el, callback) {
(0, import_jquery8.default)(el).on(
"keyup.dateInputBinding input.dateInputBinding",
function() {
callback(true);
}
);
(0, import_jquery8.default)(el).on(
"changeDate.dateInputBinding change.dateInputBinding",
function() {
Expand Down Expand Up @@ -8510,12 +8504,6 @@
}, {
key: "subscribe",
value: function subscribe(el, callback) {
(0, import_jquery9.default)(el).on(
"keyup.dateRangeInputBinding input.dateRangeInputBinding",
function() {
callback(true);
}
);
(0, import_jquery9.default)(el).on(
"changeDate.dateRangeInputBinding change.dateRangeInputBinding",
function() {
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.

4 changes: 2 additions & 2 deletions inst/www/shared/shiny.min.js.map

Large diffs are not rendered by default.

12 changes: 4 additions & 8 deletions srcts/src/bindings/input/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,15 @@ class DateInputBindingBase extends InputBinding {
el;
}
subscribe(el: HTMLElement, callback: (x: boolean) => void): void {
$(el).on(
"keyup.dateInputBinding input.dateInputBinding",
// event: Event
function () {
// Use normal debouncing policy when typing
callback(true);
}
);
// Don't update when in the middle of typing; listening on keyup or input
// tends to send spurious values to the server, based on unpredictable
// browser-dependant interpretation of partially-typed date strings.
$(el).on(
"changeDate.dateInputBinding change.dateInputBinding",
// event: Event
function () {
// Send immediately when clicked
// Or if typing, when enter pressed or focus lost
callback(false);
}
);
Expand Down
12 changes: 4 additions & 8 deletions srcts/src/bindings/input/daterange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,15 @@ class DateRangeInputBinding extends DateInputBindingBase {
this._setMax($endinput[0], $endinput.data("max-date"));
}
subscribe(el: HTMLElement, callback: (x: boolean) => void): void {
$(el).on(
"keyup.dateRangeInputBinding input.dateRangeInputBinding",
// event: Event
function () {
// Use normal debouncing policy when typing
callback(true);
}
);
// Don't update when in the middle of typing; listening on keyup or input
// tends to send spurious values to the server, based on unpredictable
// browser-dependant interpretation of partially-typed date strings.
$(el).on(
"changeDate.dateRangeInputBinding change.dateRangeInputBinding",
// event: Event
function () {
// Send immediately when clicked
// Or if typing, when enter pressed or focus lost
callback(false);
}
);
Expand Down

0 comments on commit abf7138

Please sign in to comment.