ui5-webcomponents
ui5-webcomponents copied to clipboard
min-date and max-date as Date instead of Formatted String
Feature Request Description
It would be nice for date-picker and daterangepicker to have the option to provide the minimum and maximum date as a Date instead of the formatted date string.
It is very troublesome to format the date correctly, especially since the UI5 components use a different date notation than other major libraries (Look for example at dayjs).
Proposed Solution
To have a properties like value and date-value:
min-date-value: Minimum date as date objectmax-date-value: Maximum date as date object
Proposed Alternatives
Other way would be to allow a single formatting independent date format for min-date and max-date, like YYYY-MM-DD.
Priority
- [ ] Low
- [x] Medium
- [ ] High
- [ ] Very High
Stakeholder Info
- Organization: SAP
Hi @SAP/ui5-webcomponents-topic-b, please take a look at this feature request.
Hello @ChewbaccaCookie ,
Have you checked the formatValue method in the DatePicker( https://sap.github.io/ui5-webcomponents/playground/components/DatePicker/). I think that method will do the job for your case, as it is part of the DatePicker and it will always be up to date with the current format used. It's a method which receives a JS Date Object and returns a string with the date in the required by the DatePicker format.
Can you please check if this solution will work for you and get back to us?
Best Regards, Tsanislav
Hello @tsanislavgatev, yes, this is possible to use, but not very common. I would expect, that I can set the min and max date formatting and localization independent. In React we've to use the reference of this component, only to format the date in a correct format, which is very strange. Thank you
Hello @ChewbaccaCookie, Having it with a single date format, will cause difference between different APIs, for example, having it DD/MM/YYYY for all locales, or formatPatterns. This will cause having value and min/max dates with different string formats, which is a non consistent behaviour. That's why we have suggested using the format. Setting a formatPattern should also help having all properties expecting the same format. Can you please take a look if one of the two suggested solutions can help you solving the case?
Best Regards, Tsanislav
We've now used the formatValue method. It works. Thank you