Repository navigation
fix: dateInput() datesdisabled ignored non-default format (#4281) - #4434
Conversation
bootstrap-datepicker's setDatesDisabled() re-parses the input text with the display format, turning 2-digit years like 12 into year 12 AD. Apply it before setValue(), and omit the attribute when datesdisabled is NULL.
|
Thanks for catching this, and for the precise repro and cause. Pushed a follow-up commit:
Verification: with your repro app (plus one input with The new shinytest2 test passes on this commit (6/6) and fails 3 expectations on the previous one (both |
cpsievert
left a comment
There was a problem hiding this comment.
Thanks @taekop! Would you be willing to make the same change to input_date() in https://github.com/posit-dev/py-shiny ?
Also, now that I think of it, do we need similar changes for dateRangeInput()?
|
Thanks for the review! I checked For py-shiny, |
That would be awesome, thanks! |
Emit data-dates-disabled instead of data-date-dates-disabled so the dates are parsed as yyyy-mm-dd by the client binding rather than by bootstrap-datepicker with the display format. Omit the attribute when datesdisabled is None. Update InputDate.expect_datesdisabled() to match. Needs the shiny.js from rstudio/shiny#4434.
|
The py-shiny port is up in posit-dev/py-shiny#2523. |
Fixes #4281, #3251.
dateInput()'sdatesdisabledsilently did nothing wheneverformatwasn'tthe default
yyyy-mm-dd.min/maxavoid this problem by sending yyyy-mm-ddstrings through a plain
data-min-date/data-max-dateattribute, which theclient-side binding converts to real
Dateobjects before handing them tobootstrap-datepicker.
datesdisabled, on the other hand, was rendered asdata-date-dates-disabled, adata-date-*attribute that bootstrap-datepickerpicks up and parses itself using the (possibly non-default) display format —
so a yyyy-mm-dd date string like
2012-03-01would never match onceformatwas, say,
dd/mm/yyyy.This renames the attribute to a plain
data-dates-disabledand has theclient-side date binding convert each entry the same way
min/maxalreadyare (via
_newDate), before calling bootstrap-datepicker'ssetDatesDisabledwith real
Dateobjects.daysofweekdisabledis untouched since it's justintegers and has no format dependency.
updateDateInput()doesn't currentlysupport updating
datesdisabledat all, so there's no correspondingreceiveMessagepath to fix.The disabled dates are applied before the initial value is set in
initialize(), because bootstrap-datepicker'ssetDatesDisabled()re-parsesthe input text with the display format (which misreads 2-digit years). The
attribute is omitted when
datesdisabledisNULL, likemin/max.Tests:
tests/testthat/test-input-date.Rchecks the rendered attribute, andtests/testthat/test-zzz-st2-input-date.R(shinytest2) checks the server valueand the disabled days for
dd/mm/yyyyandmm/dd/yy, with and withoutdatesdisabled.