Skip to content

Commit abf7138

Browse files
dvg-p4gadenbuie
andauthored
Fix sporadic dates (#3664) (#3665)
* 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 <garrick@adenbuie.com>
1 parent 2e2114f commit abf7138

File tree

7 files changed

+15
-33
lines changed

7 files changed

+15
-33
lines changed

NEWS.md

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

1313
* 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)
1414

15+
* `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)
16+
1517
# shiny 1.9.1
1618

1719
## Bug fixes

inst/www/shared/shiny.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8061,12 +8061,6 @@
80618061
}, {
80628062
key: "subscribe",
80638063
value: function subscribe(el, callback) {
8064-
(0, import_jquery8.default)(el).on(
8065-
"keyup.dateInputBinding input.dateInputBinding",
8066-
function() {
8067-
callback(true);
8068-
}
8069-
);
80708064
(0, import_jquery8.default)(el).on(
80718065
"changeDate.dateInputBinding change.dateInputBinding",
80728066
function() {
@@ -8510,12 +8504,6 @@
85108504
}, {
85118505
key: "subscribe",
85128506
value: function subscribe(el, callback) {
8513-
(0, import_jquery9.default)(el).on(
8514-
"keyup.dateRangeInputBinding input.dateRangeInputBinding",
8515-
function() {
8516-
callback(true);
8517-
}
8518-
);
85198507
(0, import_jquery9.default)(el).on(
85208508
"changeDate.dateRangeInputBinding change.dateRangeInputBinding",
85218509
function() {

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/date.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,15 @@ class DateInputBindingBase extends InputBinding {
4040
el;
4141
}
4242
subscribe(el: HTMLElement, callback: (x: boolean) => void): void {
43-
$(el).on(
44-
"keyup.dateInputBinding input.dateInputBinding",
45-
// event: Event
46-
function () {
47-
// Use normal debouncing policy when typing
48-
callback(true);
49-
}
50-
);
43+
// Don't update when in the middle of typing; listening on keyup or input
44+
// tends to send spurious values to the server, based on unpredictable
45+
// browser-dependant interpretation of partially-typed date strings.
5146
$(el).on(
5247
"changeDate.dateInputBinding change.dateInputBinding",
5348
// event: Event
5449
function () {
5550
// Send immediately when clicked
51+
// Or if typing, when enter pressed or focus lost
5652
callback(false);
5753
}
5854
);

srcts/src/bindings/input/daterange.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,19 +161,15 @@ class DateRangeInputBinding extends DateInputBindingBase {
161161
this._setMax($endinput[0], $endinput.data("max-date"));
162162
}
163163
subscribe(el: HTMLElement, callback: (x: boolean) => void): void {
164-
$(el).on(
165-
"keyup.dateRangeInputBinding input.dateRangeInputBinding",
166-
// event: Event
167-
function () {
168-
// Use normal debouncing policy when typing
169-
callback(true);
170-
}
171-
);
164+
// Don't update when in the middle of typing; listening on keyup or input
165+
// tends to send spurious values to the server, based on unpredictable
166+
// browser-dependant interpretation of partially-typed date strings.
172167
$(el).on(
173168
"changeDate.dateRangeInputBinding change.dateRangeInputBinding",
174169
// event: Event
175170
function () {
176171
// Send immediately when clicked
172+
// Or if typing, when enter pressed or focus lost
177173
callback(false);
178174
}
179175
);

0 commit comments

Comments
 (0)