mui / mui/base-ui

[field] Improve error message customization involving multiple validation rules

Open
#1,923 4 comments 0 reactions 0 assignees View on GitHub
component: field type: enhancement
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.