Skip to content

[Signal Forms] Update min and max to operate on number and Date values#68001

Closed
leonsenft wants to merge 7 commits into
angular:mainfrom
leonsenft:sf-min-max-date
Closed

[Signal Forms] Update min and max to operate on number and Date values#68001
leonsenft wants to merge 7 commits into
angular:mainfrom
leonsenft:sf-min-max-date

Conversation

@leonsenft
Copy link
Copy Markdown
Contributor

@leonsenft leonsenft commented Apr 2, 2026

  • Remove string support from min and max validation rules. This is no longer necessary since FormField can bind a numeric field to a text based control.
  • Add minDate and maxDate validation rules. These will bind min and max properties as formatted strings for date and month type inputs only.

@leonsenft leonsenft requested a review from alxhub April 2, 2026 18:29
@leonsenft leonsenft added area: forms target: patch This PR is targeted for the next patch release forms: signals labels Apr 2, 2026
@ngbot ngbot Bot added this to the Backlog milestone Apr 2, 2026
@pullapprove pullapprove Bot requested review from AndrewKushnir April 2, 2026 18:30
@angular-robot angular-robot Bot added the detected: breaking change PR contains a commit with a breaking change label Apr 2, 2026
@leonsenft leonsenft added target: minor This PR is targeted for the next minor release and removed target: patch This PR is targeted for the next patch release labels Apr 2, 2026
Comment thread goldens/public-api/forms/signals/index.api.md Outdated
Comment thread packages/forms/signals/src/api/rules/validation/validation_errors.ts Outdated
Comment thread packages/forms/signals/src/api/rules/metadata.ts Outdated
@pullapprove pullapprove Bot requested a review from JeanMeche April 2, 2026 20:35
@leonsenft leonsenft requested a review from alxhub April 2, 2026 22:09
Comment thread packages/forms/signals/test/web/form_field.spec.ts
Copy link
Copy Markdown
Contributor

@jnizet jnizet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like my date input fields to be bound to iso date strings (which is the default native value of date inputs). Iso dates lexicographic order is also the chronological order. Can't min and max be applied to them?

@martijnmelchers
Copy link
Copy Markdown

Does this work properly with time inputs? They expect a string like "09:00" (see: https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/input/time)

The `min` and `max` validation rules previously handled `string` values
to accommodate numbers bound to text inputs. However, this is no longer
necessary as the control binding itself handles the conversion.

This change removes string support from these rules, simplifying the
types to `number | null`. The validation logic has been updated to use
concrete checks (`value === null || Number.isNaN(value)`) to ensure safe
TypeScript narrowing.

Associated tests have been updated to:
- Remove string-specific validation checks.
- Add coverage for text input bindings.
- Add coverage for empty input handling (standard behavior where empty
  sets model to null and skips validation).

BREAKING CHANGE: `min` and `max` validation rules no longer support
string values. Bound values must be numbers or null.
leonsenft added 2 commits May 5, 2026 14:37
- Added `minDate()` and `maxDate()` for validating constraints on `Date` inputs.
- `ReadonlyFieldState.min` and `.max` now return
  `Signal<NonNullable<TValue>`. This ensures that `min` and `max` inputs
  on custom controls can accept a reliable type (matching their value
  type).
- Made the `TWrite` type parameter of `MetadataKey` contravariant to
  properly indicate that it's writable.
- Added `LimitKey` as a convenience type for defining validation limit
  metadata (e.g. `MAX_NUMBER`, `MIN_DATE`).
- Added `LimitSelectionKey` which can be used to bind a `LimitKey` with
  value-specific aggregation logic, to a generic metadata key (e.g. use
  `MAX_NUMBER` to aggregate numbers for `MAX`).
…te`/`maxDate`

* Test that `minDate`/`maxDate` binds to `min`/`max` on date and time inputs
* Test that `min`/`max` attribute can be set directly on date and time inputs
* Relax type checker to allow `min`/`max` bindings on date and time inputs
@leonsenft
Copy link
Copy Markdown
Contributor Author

leonsenft commented May 5, 2026

@jnizet @martijnmelchers I've made changes to better accommodate date and time formats.

  • For type="date" and type="month" inputs, we format date values to the expected string format for min and max.
  • The type checker has been relaxed to allow binding the min and max properties manually in the template for date and time inputs since we can't support all formats without taking dependencies on external date/time libraries (until Temporal is widely available).

@leonsenft leonsenft removed this from the Backlog milestone May 6, 2026
@leonsenft leonsenft added this to the v22 candidates milestone May 6, 2026
Copy link
Copy Markdown
Member

@alxhub alxhub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed-For: fw-general, public-api

Copy link
Copy Markdown
Member

@alxhub alxhub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed-for: public-api

Copy link
Copy Markdown
Member

@alxhub alxhub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed-for: fw-compiler

@alxhub alxhub added action: merge The PR is ready for merge by the caretaker target: major This PR is targeted for the next major release and removed target: minor This PR is targeted for the next minor release labels May 6, 2026
@alxhub
Copy link
Copy Markdown
Member

alxhub commented May 6, 2026

This PR was merged into the repository. The changes were merged into the following branches:

@alxhub alxhub closed this in 592a12d May 6, 2026
alxhub pushed a commit that referenced this pull request May 6, 2026
- Added `minDate()` and `maxDate()` for validating constraints on `Date` inputs.
- `ReadonlyFieldState.min` and `.max` now return
  `Signal<NonNullable<TValue>`. This ensures that `min` and `max` inputs
  on custom controls can accept a reliable type (matching their value
  type).
- Made the `TWrite` type parameter of `MetadataKey` contravariant to
  properly indicate that it's writable.
- Added `LimitKey` as a convenience type for defining validation limit
  metadata (e.g. `MAX_NUMBER`, `MIN_DATE`).
- Added `LimitSelectionKey` which can be used to bind a `LimitKey` with
  value-specific aggregation logic, to a generic metadata key (e.g. use
  `MAX_NUMBER` to aggregate numbers for `MAX`).

PR Close #68001
alxhub pushed a commit that referenced this pull request May 6, 2026
…te`/`maxDate` (#68001)

* Test that `minDate`/`maxDate` binds to `min`/`max` on date and time inputs
* Test that `min`/`max` attribute can be set directly on date and time inputs
* Relax type checker to allow `min`/`max` bindings on date and time inputs

PR Close #68001
@leonsenft leonsenft deleted the sf-min-max-date branch May 6, 2026 20:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: forms detected: breaking change PR contains a commit with a breaking change forms: signals target: major This PR is targeted for the next major release

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants