[field] Improve error message customization involving multiple validation rules
- Dominant language
- TypeScript
- Stars
- 10.9k
- Forks
- 543
- Avg merge
- 1d 20h
- Merged PRs (30d)
- 101
Description
Sandbox: https://codesandbox.io/p/sandbox/jovial-feather-knsgk4
When a field has multiple validation rules (e.g. `required`, `minLength`, `maxLength`, `pattern`) and you want to customize some but not all of the error messages, it's not possible to exclude the customized ones from being displayed in the default child-less ``:
```jsx
// this one will display the default `required` error message
// these 2 validityStates will display the error twice
Alphanumeric characters and symbols only
At least 2 characters
```
The errors using a default message would each have to use an individual component with `match` and no children (e.g. ``) which is a bit annoying
Not sure if this will over-complicate `match` (esp with additional `boolean` support) but maybe support a function (returning `string | boolean`) as well?😅
```jsx
['patternMismatch', 'tooShort'].includes(validityState)} />
```
Contributor guide
Assessment
This issue has not been assessed yet.