DataForm: Add min/max date range support for date and datetime fields#77201
DataForm: Add min/max date range support for date and datetime fields#77201jorgefilipecosta merged 31 commits intotrunkfrom
Conversation
|
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
f62d531 to
be19d20
Compare
|
Size Change: +1.7 kB (+0.02%) Total Size: 7.74 MB 📦 View Changed
ℹ️ View Unchanged
|
|
Flaky tests detected in e763a03. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/24411530597
|
27ba39d to
03fa436
Compare
| @@ -1,3 +1,4 @@ | |||
| /// <reference types="@wordpress/jest-console" /> | |||
There was a problem hiding this comment.
It was to make a test have no lint errors, but I pushed a change that resolves that in other way.
|
I pushed a simplification for types at 48ce837 Let me know if there's something I've missed from the previous version. |
Allow date and datetime fields to use string-based min/max constraints (e.g., '2017-04-01') alongside the existing numeric constraints used by integer and number fields.
Update get-is-valid.ts to normalize min/max constraints when the value is a string (for date fields), not just when it is a number (for integer/number fields).
Create a date-specific min validator that compares string values using ISO date string comparison (e.g., '2017-04-01' >= constraint). Follows the same pattern as the existing isValidMin for numbers.
Create a date-specific max validator that compares string values using ISO date string comparison (e.g., value <= '2017-04-20'). Follows the same pattern as isValidMinDate and isValidMax.
Import and wire isValidMinDate/isValidMaxDate into the date field type's validate object so min/max constraints are normalized and enforced for date fields.
Import and wire isValidMinDate/isValidMaxDate into the datetime field type's validate object, matching the date field type setup.
Pass min/max to native HTML date inputs and build disabled matchers for DateCalendar and DateRangeCalendar to visually disable out-of-range dates. Applies to both single date and date range (between operator) controls.
Pass min/max to native datetime-local input (converted via formatDateTime) and build disabled matchers for DateCalendar to visually disable out-of-range dates.
Update the validation story to demonstrate min/max constraints on date, dateRange, and datetime fields when the minMax arg is toggled. Uses Apr 1-20, 2017 as the example range.
Use 2026-04-01 to 2026-04-20 instead of 2017 so the example dates are in the future and easier to test interactively.
Use || instead of ?? so disabled=true always takes precedence over date range matchers.
6f55143 to
a76b743
Compare
Looks good, thank you! |
Summary
minandmaxvalidation constraints ondateanddatetimeDataForm fields, similar to HTML's native<input type="date" min="2017-04-01" max="2017-04-20">Rules.min/maxtypes fromnumbertonumber | stringso date fields can use string-based constraints alongside numeric fieldsisValidMinDate,isValidMaxDate) that use ISO string comparisonmin/maxon HTML inputs anddisabledmatchers onDateCalendar/DateRangeCalendarminMaxarg is toggledcc: @oandregal
How it works
Test plan
?path=/story/dataviews-dataform--validation&args=minMax:!truenpm run test:unit packages/dataviews/— all tests pass