Improve ui.date returning a dictionary #2904
Replies: 1 comment 1 reply
-
Thanks for the suggestion, @Nemecsek! I agree that the different datatypes ( Maybe date ranges justify a new element |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
The current version of
ui.date
returns:mask
This code found at Input Element with Date Picker returns a valid date string when a single day is chosen, but reads [object Object] instead when a range is selected because it cannot render the dictionary as a string:
A workaround to embed the code to transform the range dictionary to a string (provided by @falkoschindler, because I couldn't work out a solution on my own) could be the following one, but it is not for the fainthearted:
I would prefer
ui.date
always to return a dictionary, even if this breaks compatibility:{ "no_of_days":0, "value":"Please select a day" }
{ "no_of_days":1, "value":"Mai 23, 2024", "date":datetime(2024, 5, 23) }
{ "no_of_days":5, "value":"Mai 23-27, 2024",
"date_from":datetime(2024, 5, 23), "date_to":datetime(2024, 5, 27) }
This is a possible new API:
ui.date(mask="MMM DD, YYYY", remove_common=True, range_separator="-", invalid_text="Please select a day")
mask
to formats both a single day and day_start/day_end in a range;remove_common
removes the common part in a range to make the string more readable:i.e.
May 23, 2024-June 7, 2024
becomesMay 23-June 7, 2024
because the year is the same;May 23, 2024-May 27, 2024
becomesMay 23-27, 2024
because the year and the month are the same.range_separator
: the string between day_start and day_end (i.e...
,-
or/
)invalid_text
: the text to return in case no day is selected.Beta Was this translation helpful? Give feedback.
All reactions