Skip to content

Field API: Validation #71500

@oandregal

Description

@oandregal

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 elements validation 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 set elements: true to 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:

  • Use ValidatedInputControl for date field type (support for required & custom validation)
  • Use ValidatedInputControl for datetime field type (support for required & custom validation)
  • Implement isValid.pattern validation #73156
  • Implement isValid.min/isValid.max validation #73465

Metadata

Metadata

Labels

[Package] DataViews/packages/dataviews[Type] Tracking IssueTactical breakdown of efforts across the codebase and/or tied to Overview issues.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions