Skip to content

feat(forms): date and datetime-local minimum/maximum bounds - #697

Merged
jimhoyd merged 1 commit into
mainfrom
feat/forms-date-bounds
Sep 25, 2026
Merged

jimhoyd merged 1 commit into
mainfrom
feat/forms-date-bounds

Conversation

@jimhoyd

@jimhoyd jimhoyd commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

Part of #528. This PR does the date-range half. Conditional validation is still open.

What changes

  • minimum / maximum now also bound type: date and type: datetime-local fields, written in the field's own format. Bounds are inclusive and either side can be left out.
    startDate: {label: Start date, type: date, minimum: "2026-01-01", maximum: "2027-12-31"}
    callback:  {label: Callback, type: datetime-local, minimum: "2026-01-05T09:00", maximum: "2026-01-09T17:30"}
  • Activation refuses a bound that is not a real date or time in the field's format, a minimum later than maximum, a string bound on a number field, and any bound on other types.
  • Submission: the format is checked first, then the bounds. The comparison is at full precision (09:00 = 09:00:00.000, 17:30:00.001 > 17:30), and an out-of-range value gets a 422 field error: "must be on or after …" / "must be on or before …".
  • Rendering: date inputs get the matching HTML min / max. This adds min / max options to ui's field(), which accepts them only on number, date and datetime-local inputs, only with number- or date-shaped values, and always escapes them.

Why reuse minimum / maximum rather than add min / max

A field already has exactly one value bound: minimum / maximum. The field's type already decides what those bounds mean. Adding a second pair would mean either pair could appear on the wrong type, and both would need cross-refusal rules. Reusing the keys keeps the vocabulary JSON-Schema-shaped like the rest of fieldSchema (minLength, pattern, enum). YAML 1.2 (the yaml package) keeps unquoted 2026-01-01 as a string, so authors can leave dates unquoted. The README examples quote them anyway, to be safe.

Deliberate narrowing

  • datetime-local bounds are whole minutes. Browsers use min as the step base, and the default step is 60 s. A bound with seconds would make the picker reject ordinary values while the server accepted them.
  • Numeric bounds are still enforced by the server only. They are not rendered as min / max, because with the default step=1 a fractional minimum would make browsers reject valid values.
  • Relative bounds ("today", "+2 years") are out of scope and remain a follow-up under [Gap]: add bounded conditional and date-range validation to forms #528.

Note on the triage comment

The triage comment on #528 retained the issue as evidence-gathering only. This PR implements the absolute date-range subset on the owner's direction in this session. The issue body lists that subset as an acceptable bounded shape ("field-local RFC 3339 date validator with explicit absolute/relative bounds").

Evidence

  • npm run typecheck: pass
  • packages/forms tests: 17/17, including two new [Gap]: add bounded conditional and date-range validation to forms #528 tests (submission, rendering, activation refusals)
  • packages/ui tests: 96/96, including a new field() min/max test
  • npm run verify: exit 0. This covers lint, typecheck, check, core tests 799/799, every workspace's verify, the add-on manifest check (packages/forms/urlcode.json regenerated), package audit and add-on integration.

CI passing is not a security review.

🤖 Generated with Claude Code

minimum and maximum were numeric-only and refused on any non-number
field. They now also bound type: date (a YYYY-MM-DD string) and
type: datetime-local (a whole-minute YYYY-MM-DDTHH:MM string), in the
field's own format, inclusive, either side optional.

- Activation refuses a bound that is not a real date/time in the
  field's format, a minimum later than maximum, a string bound on a
  number field, and any bound on other types.
- Submission compares at full precision (09:00 == 09:00:00.000) and
  answers 422 with "must be on or after/before <bound>".
- The input renders matching HTML min/max via a new ui field() min/max
  option, restricted to number/date/datetime-local inputs.
- datetime-local bounds are whole minutes because browsers use min as
  the step base and the default 60 s step would otherwise reject
  ordinary values.

Relative bounds ("today") and conditional validation remain out of
scope. Part of #528.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@jimhoyd
jimhoyd merged commit a8098d8 into main Sep 25, 2026
19 checks passed
@jimhoyd
jimhoyd deleted the feat/forms-date-bounds branch September 25, 2026 00:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant