Closed dvg-p4 closed 1 month ago
With format set to "mm/dd/yyyy", this is arguably even worse--it'll try to set itself to the year AD 202, 20, and 2, as you try to backspace out the year.
I can confirm that this is a problem as stated by @dvg-p4 , particularly evident where there are a pair of dateInput
and where observeEvent
has been set up to make sure that the dates are not inconsistent e.g. date_from
is not greater than date_to
.
Some of the worst effects of this problem can be reduced by setting min
and max
for the dateInput
, but it doesn't solve all problems, since a valid date may still be detected by dateInput
, even when the user has not completed typing in the date.
System details
Browser Version: RStudio, Google Chrome
Output of
sessionInfo()
:Example application or steps to reproduce the problem
```R library(shiny) shinyApp( ui = basicPage( textOutput("date_out"), dateInput("date_in", "Date input", "2000-01-01") ), server = function(input, output, session) { output$date_out <- renderText(as.character(input$date_in)) } ) ``` Click into the text field of the date input and press backspace; the date displayed will be 1999-12-31. Press backspace again; it will be today's date. Continue pressing backspace; it will be null when the field is empty. ### Describe the problem in detail `dateInput` (and `dateRangeInput`) eagerly try to parse incomplete date strings as they are being typed, and then send off the results to the server. This can have the effect of the server trying to process a date completely different from the one that the user intended to enter. In the case of a range, this can result in a min and max in the wrong order; and with a cleared-out field that the user intends to start typing a new date in, the server sees a null value. The server will then take actions with the bogus date before the user is even finished typing (some of which may prevent the user from completing their typing, e.g. updating the input to be in the "correct" order or throwing an error for a null date). This might stem from JavaScripts officially undefined behavior when parsing nonstandard datestrings; I'd recommend ignoring typed input in this field until the user presses enter or unfocuses the field; or only updating when the current string matches the set format.