-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Description
Related: #72321
What
This is a tracking issue to break down the work on implementing validation in the Field API.
See related iteration issue and tracking issues for WordPress 6.9 and WordPress 7.0, as well as the comparison of validation in JSON Schema, Fields API, and HTML.
Goals
Support a number of general validation rules leveraging the HTML standard. If/when we introduce domain-specific types (e.g., slug), that would also support domain-specific validation. For the 1st iteration, we want to implement general validation, while supporting domain-specific validation via the isValid.custom.
Support both sync and async custom validation. In progress: controlled, uncontrolled.
Status
- not planned:
- - need to be implemented: empty cell
- shipped: ✅
| required | custom | pattern | min/max | elements[1] | |
|---|---|---|---|---|---|
| array (field type & control) | ✅ | ✅ | - | - | ✅ |
| boolean (field type) | ✅ | ✅ | - | - | - |
| checkbox (control) | ✅ | ✅ | - | - | - |
| color (field type & control) | ✅ | ✅ | - | - | - |
| date (field type & control) | Use validated control | Use validated control | - | range of dates | - |
| datetime (field type & control) | Use validated control | Use validated control | - | range of dates | - |
| email (field type & control) | ✅ | ✅ | ✅ | max=maxlength, min unsupported | - |
| integer (field type & control) | ✅ | ✅ | - | controls the range of input | - |
| media (field type & control) | - | - | - | - | - |
| password (field type & control) | ✅ | ✅ | ✅ | controls the length of input (min=minlength, max=maxlength) | - |
| radio (control) | ✅ | ✅ | - | - | - |
| select (control) | ✅ | ✅ | - | - | - |
| telephone (field type & control) | ✅ | ✅ | ✅ | - | - |
| text (field type & control) | ✅ | ✅ | ✅ | controls the length of input (min=minlength, max=maxlength) | - |
| textarea | ✅ | ✅ | - | - | - |
| toggle (control) | ✅ | ✅ | - | - | - |
| toggleGroup (control) | ✅ | ✅ | - | - | - |
| url (field type & control) | ✅ | ✅ | ✅ | - | - |
Notes:
- [1] The
elementsvalidation rule is something we have hardcoded in the custom function of some field types (example) and we aim to extract. In some contexts, the UI component would restrict already the inputs (e.g., via select component) but others would require to setelements: trueto make it so (e.g., ValidatedFormTokenField for array).
Tasks
Any of these can be picked up by anyone. Refer to the status table above for details: