[Signal Forms] Update min and max to operate on number and Date values - #68001
[Signal Forms] Update min and max to operate on number and Date values#68001leonsenft wants to merge 7 commits into
min and max to operate on number and Date values#68001Conversation
b3c23ef to
7e32650
Compare
jnizet
left a comment
There was a problem hiding this comment.
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?
|
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) |
de24419 to
f442288
Compare
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.
- 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
… `minDate`/`maxDate`
… `minDate`/`maxDate`
|
@jnizet @martijnmelchers I've made changes to better accommodate date and time formats.
|
alxhub
left a comment
There was a problem hiding this comment.
Reviewed-For: fw-general, public-api
|
This PR was merged into the repository. The changes were merged into the following branches:
|
- 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
|
This pull request has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
stringsupport fromminandmaxvalidation rules. This is no longer necessary sinceFormFieldcan bind a numeric field to a text based control.minDateandmaxDatevalidation rules. These will bindminandmaxproperties as formatted strings fordateandmonthtype inputs only.