-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
Library
React / v8 (@fluentui/react)
Describe the feature that you would like added
It's currently not possible to show custom error messages in DatePickers that aren't related to built-in validation mechanisms. My proposal would be an equivalent to the errorMessage field that exists on almost all other form fields.
My user story is as follows:
I currently have two different datepickers that're related to each other. We have a bit of form-level validation, which throws a validation error if one date is before the other (A daterange picker is not in order, as one doesn't have to supply both fields and it wouldn't make contextual sense to have both in the same datepicker).
I.e. I want to show an error that isn't related to a missing or an "invalid" input, "invalid" in the sense that the input value isn't a valid date.
This would allow users to show business level validation logic right below the affected datepicker.
Alternatives I considered
Custom validation trigger
I tried to abuse the current invalidInputErrorMessage to work around this issue, but I couldn't find a way to have the Datepicker display the error message if the input was actually a "valid" date.
Setting dynamic boundaries
I tried to set a min_date based on the other datepicker.
This is a bit tricky, as the validation error message must also be adjusted accordingly to give the user some context on why this input is invalid. This gets even more tricky if one is doing backend validation, as we now have to double-implement the validation logic. The frontend needs to know when to show the error message, whilst the backend supplies the validation error.
It would be much easier to just be able to provide a string via "errorMessage" which always shows an error.
Have you discussed this feature with our team
No response
Additional context
There has already been a related issue for this quite a bit of time ago, but it was closed after the creator was pointed to IDatePickerStrings. #3089
Right now, it's possible to set a few custom strings via the strings: IDatePickerStrings interface on DatePicker.
This only exposes a few fields for translation purposes:
invalidInputErrorMessageisRequiredErrorMessageisOutOfBoundsErrorMessageisResetStatusMessage
https://developer.microsoft.com/en-us/fluentui#/controls/web/datepicker#IDatePickerStrings
However, I couldn't find a way to run custom logic to trigger one of those strings to be displayed.
Validations
- Check that there isn't already an issue that request the same feature to avoid creating a duplicate.