Commit graph

73 commits

Author SHA1 Message Date
Alan Agius
7907e982ee test: remove duplicate tests
These tests are duplicate and have been removed.
2026-03-11 13:35:26 -07:00
Leon Senft
567f292e8e fix(forms): support custom controls as host directives
Add the missing code to update control properties when control is a host
directive.

Fix #66592.
2026-02-18 14:06:54 -08:00
Leon Senft
dcb9af6dfa test(forms): [formField] synchronizes with a host directive
Test that `[formField]` synchronizes its value with a custom form
control implemented as a host directive on a component.
2026-02-18 14:06:54 -08:00
Miles Malerba
30f0914754 feat(forms): support binding null to number input (#66917)
Supports binding `null` to a `<input type=number>`.

- Binding in `null` clears the input
- Binding in `NaN` also clears the input
- When the user clears the input, the model is set to `null`
- The model is _never_ set to `NaN` based on user interaction. It is
  either set to `null` if the user cleared the input, or is unchanged
  and a parse error added if the user entered an invalid number like
  "42e"

PR Close #66917
2026-02-13 12:11:06 -08:00
Miles Malerba
22afbb2f36 feat(forms): add parsing support to native inputs (#66917)
Integrates native inputs with the new parseErrors API so that they can
report parse errors when the user types an un-parsable value (e.g. "42e"
in a number field).

When a user types an un-parsable value, the model does not update. It
retains its previous value and a parse error is added for the control
that received the un-parsable value.

PR Close #66917
2026-02-13 12:11:06 -08:00
cexbrayat
63d8005703 fix(forms): preserve custom-control focus context in signal forms
Fixes #67051

Store custom control focus callbacks in a wrapper so method invocation keeps the original object context. Without this, custom focus methods that access instance members throw at runtime when focusBoundControl() is called.
2026-02-13 09:37:19 -08:00
Miles Malerba
d75046bc09
fix(forms): warn when showing hidden field state
In signal forms, it is up to the user to guard hidden fields from being
rendered in the template. To help catch instances where it is
accidentally not guarded, this commit introduces a warning in dev mode.
2026-02-11 14:46:43 -08:00
Leon Senft
3606902b33
refactor(forms): relax [formField] input type from FieldTree to Field
`FieldTree` was an unnecessarily specific type for the `[formField]`
input. It forced the directive to care about what _kind_ of `FieldTree`
was bound–specifically whether it was Reactive Forms compatible or not.
This made it difficult to author forms system-agnostic components with
passthrough `[formField]` inputs.
2026-02-11 11:45:20 -08:00
kirjs
c750b3cf11 refactor(forms): Setup closure compatible property override
We have to do this because Abstract control doesn't allow us to have value as a getter type-wise
2026-02-02 14:51:40 -08:00
kirjs
bbbdf0a6ed refactor(forms): add unsupported method errors and docs
- Add disable, enable methods that throw with helpful messages
- Add validator methods (set/add/remove/clear) that throw
- Add setErrors, markAsPending methods that throw
- Add setters for dirty/pristine/touched/untouched that throw
- Add JSDoc with @usageNotes examples
- Add comprehensive unit tests for SignalFormControl
- Add FormGroup/FormArray integration tests
- Add web tests for CVA directive lifecycle
- Update migration docs with SignalFormControl usage
2026-02-02 14:51:40 -08:00
Miles Malerba
ebae211add feat(forms): introduce parse errors in signal forms
Parse errors allow a custom control to communicate that it is currently
unable to produce a valid value.

Parse errors are reported by implementing the optional `parseErrors`
property on the `FormUiControl`. The property should be a signal of the
current parse errors.

Also renames several `*Field` types to `*FieldTree`. This aligns with the new naming of the concept after `Field` was renamed
to `FieldTree`.
2026-01-22 22:19:10 +00:00
SkyZeroZx
95c386469c feat(forms): Add passing focus options to form field
Extends the `focus` method of form fields and custom controls to accept and propagate `FocusOptions`.

This enables developers to control focus behavior more precisely, for example, preventing scrolling when focusing an element.
2026-01-16 13:24:27 -08:00
Miles Malerba
5974cd0afc
feat(forms): Ability to manually register a form field binding in signal forms
This PR adds the ability to manually register a binding with the
`FormField` directive. This is useful for a lower-level implementation
that takes the field tree as an `input()` rather than relying on the
automatic binding from `FormUiControl`.
2026-01-15 11:03:28 -08:00
Matthieu Riegler
65fa5b5439 fix(forms): Ensure the control instruction comes after the other bindings
Prior to this change, binding to radio value was sensitive to the order in which `value` & `formField` where binding in the template.
The compiler change makes that order non-important.

fixes #66402
2026-01-12 13:49:19 -08:00
Miles Malerba
10e9022a07 feat(forms): allow focusing bound control from field state
Allows focusing the assocated bound control from the `FieldState`.
2026-01-12 09:59:42 -08:00
Miles Malerba
5671f2cc07
fix(forms): Rename signal form [field] to [formField]
This completes the rename started in #66136. `[field]` is too generic of
a selector for the forms system to own, and likely to cause naming
collisions with existing components. Therefore it is being renamed to
`[formField]`
2026-01-09 14:33:09 -08:00
Miles Malerba
2d85ae5811 feat(forms): add [formField] directive
This will replace the `[field]` directive, since `[field]` is a very
generic name for signal forms to commandeer

refactor(forms): hook up `formField` directive in compiler

Hooks up the `formField` direcive to get the same treatment as the
`field` directive in the compiler.

apply updated formatting
2026-01-06 17:21:06 -05:00
Leon Senft
82a2de201f refactor(forms): bind native properties on interop controls
The framework will now bind all field state properties to their
corresponding native properties (if any) on interop form controls (those
using `ControlValueAccessor`), excluding those handled explicitly by
`ControlValueAccessor` such as `disabled`.
2026-01-06 13:12:17 -05:00
Leon Senft
15bddbdcda refactor(forms): bind field properties to all directives on interop controls
The framework will now bind the field state properties to all matching
directive inputs on form controls using Reactive Forms'
`ControlValueAccessor`.
2026-01-06 13:12:17 -05:00
Leon Senft
0c8f15d546 refactor(forms): bind field properties to all directives on custom controls
The framework will now bind the field state properties to all matching
directive inputs on custom form controls.
2026-01-06 13:12:17 -05:00
Leon Senft
c149f47ef6 refactor(forms): bind field properties to all directives on native controls
Since the `Field` directive manages binding `FieldState` properties to
the underlying form control automatically, the type checker prohibits
explicit bindings to the same properties to avoid conflicts. This proved
problematic in cases where developers wanted to bind these properties to
the inputs of other directives on form controls. Now the framework will
bind the field state properties to all matching directive inputs on
native controls.

Fix #65617
2026-01-06 13:12:17 -05:00
Leon Senft
e7745dc9dd test(forms): add test coverage for binding errors to custon controls
This input was missing dedicated test coverage.
2026-01-02 08:09:35 +01:00
Leon Senft
8832fc01b2 test(forms): remove duplicate test case
We had two test cases that tested the `Field` directive synchronizes
with a custom checkbox control components.
2026-01-02 08:09:35 +01:00
Leon Senft
1a4c3eb1d0 fix(forms): allow custom controls to require pending input
* Allow custom controls to make `pending` a required input
* Refactor test for `pending` input to be consistent with other control
  properties
* Test that `pending` inputs are reset when the field binding changes
2026-01-02 08:09:35 +01:00
Leon Senft
9ad603fa11 test(forms): remove obsolete test case
There's no longer a need to test that inputs are set before
initialization on custom controls now that required inputs are
supported.
2026-01-02 08:09:35 +01:00
Leon Senft
4f73a350a5 test(forms): refactor and improve test coverage for disabledReasons input
* Refactor test for `disabledReasons` input to be consistent with other control
  properties
* Test that `disabledReasons` inputs are reset when the field binding changes
2026-01-02 08:09:35 +01:00
Leon Senft
89c37f1f7f fix(forms): allow custom controls to require dirty input
* Allow custom controls to make `dirty` a required input
* Refactor test for `dirty` input to be consistent with other control
  properties
* Test that `dirty` inputs are reset when the field binding changes
2026-01-02 08:09:35 +01:00
Leon Senft
b563b5cfc2 test(forms): refactor and improve test coverage for invalid input
* Refactor test for `invalid` input to be consistent with other control
  properties
* Test that `invalid` inputs are reset when the field binding changes
2026-01-02 08:09:35 +01:00
Leon Senft
82edf18427 fix(forms): allow custom controls to require hidden input
* Allow custom controls to make `hidden` a required input
* Refactor test for `hidden` input to be consistent with other control
  properties
* Test that `hidden` inputs are reset when the field binding changes
2026-01-02 08:09:35 +01:00
Leon Senft
cb09fb8308 fix(forms): support custom controls with non signal-based models
* Recognize directives with non signal-based models as valid custom controls
* Relax type checker to allow non signal-based models

The `FormValueControl` and `FormCheckboxControl` interfaces still
require a `model()`-input, however, a custom control need not implement
either interface to be bound by the `Field` directive.

All of the following examples can be used to define a custom control:

```ts
// Preferred: model()
class MyFormControl implements FormValueControl<string> {
  readonly value: model.required<string>();
}

// Supported: input() + output()
class MyFormControl {
  readonly value: input.required<string>();
  readonly valueChange: output<string>();
}

// Supported: @Input() + @Output()
class MyFormControl {
  @Input({required: true}) value!: string;
  @Output() valueChange: new EventEmitter<string>();
}
```

The latter two may still choose to implement `FormUiControl` for other
properties, but again it is not required.

Fix #65478
2026-01-02 08:09:03 +01:00
Matthieu Riegler
6270bba056 ci: reformat files
This is after we've slightly changed a rule in #66056
2025-12-16 14:44:19 -08:00
Miles Malerba
ae0c59028a
refactor(forms): rename field to fieldTree in FieldContext and ValidationError
BREAKING CHANGE:
2025-12-16 10:26:22 -08:00
Miles Malerba
348f149e8b feat(forms): pass field directive to class config
Updates signal forms to pass the full `Field` directive to the class
configuration functions, rather than just the state. This allows
developers to take the element as well as the state into consideration
when deciding classes to apply.

Closes #65762

BREAKING CHANGE: The shape of `SignalFormsConfig.classes` has changed

Previously each function in the `classes` map took a `FieldState`. Now
it takes a `Field` directive.

For example if you previously had:
```
provideSignalFormsConfig({
  classes: {
    'my-valid': (state) => state.valid()
  }
})
```

You would need to update to:
```
provideSignalFormsConfig({
  classes: {
    'my-valid': ({state}) => state().valid()
  }
})
```
2025-12-12 08:07:53 -08:00
kirjs
179b4cba67 fix(forms): Reuse key in parent in compat structure
This fixes the "Compat nodes do not use keyInParent." error when trying to bind compatField.
2025-12-09 12:59:22 -08:00
cexbrayat
9fe9566581 fix(forms): add signals for dirty, hidden, and pending states in custom controls
FormUiControl states that hidden, pending and dirty will be bind in custom controls, but this is currently not the case.

Fixes #65575
2025-12-08 10:30:43 -08:00
SkyZeroZx
7d1e502345 feat(forms): Allows transforms on FormUiControl signals
Extends the `FormUiControl` interface to allow `InputSignalWithTransform` in addition to `InputSignal` for its properties.

Fixes #65756
2025-12-03 15:13:01 +01:00
Leon Senft
cd7ae7e2ce fix(forms): support dynamic [field] bindings (#65599)
Support binding a `Field` directive to a component created dynamically
with `createComponent()`.

Fix #64632

PR Close #65599
2025-12-03 15:10:49 +01:00
Matthieu Riegler
f35b2ef47c refactor(compiler): Generate the controlCreate instruction after the native element has been created
This is necessary to exclude a race condition where the MutationObserver initialized by the instruction fired before the inputs are binded.

fixes #65678
2025-12-02 12:59:49 +01:00
Miles Malerba
c70e246c23
feat(forms): add DI option for classes on Field directive
Adds a DI configuration option for signal forms that allows the
developer to specify CSS classes that should be automatically added
by the `Field` directive based on the field's status.
2025-11-25 10:33:38 -05:00
Leon Senft
3a1eb07c46 fix(forms): allow dynamic type bindings on signal form controls
The type checker will no longer prohibit binding the Signal Forms `[field]`
directive to an input with a dynamic `[attr.type]` or `[type]` binding.
2025-11-25 09:15:58 -05:00
Leon Senft
f97a1d4856 refactor(forms): support custom control directives
Support binding `[field]` to directives that implement
`FormValueControl` or `FormCheckboxControl`.

The `[field]` binds to whichever directive (or component) matches first in the
event there are multiple implementations. We are considering whether to make
this an error state, which could be reported during type checking.

Closes #63910, Closes #64992
2025-11-24 13:48:17 -05:00
Leon Senft
c727df5d38
refactor(forms): reduce boilerplate needed to define custom controls
An early piece of feedback received regarding custom controls hosted on
native inputs was that they required a lot of boilerplate to bind
`FieldState` properties. Each property required an input to accept the
property, and a host binding to forward it to the native control.
2025-11-17 09:40:58 -08:00
Leon Senft
b1037ec2f0 fix(forms): debounce updates from interop controls
* Apply any debounce rules to updates from interop controls (if configured).
* Add tests to ensure debouncing works for all control types (native, custom,
  and interop).
2025-11-17 08:37:26 -08:00
Leon Senft
acb78eeb7a test(forms): [field] inputs on components should just pass through
Test that a component with a bound `[field]` input is not treated as a
control, and that `fieldBinding` does not include the corresponding
`Field` instance.
2025-11-14 08:37:42 -08:00
Kristiyan Kostadinov
10915f2f5f test(forms): fix type checking errors in signal form tests
Fixes some type checking errors in the signal forms tests that accumulated while there wasn't any type checking.
2025-11-07 11:57:50 -08:00
Miles Malerba
fa02d96508
test(forms): re-enable some disabled tests
Adjusts test behavior to reflect current implementation and enables them
2025-11-06 09:41:28 -08:00
Miles Malerba
194b41199b refactor(forms): improved select support
When we set the `value` on a `<select>` element we're really just
setting the selected `<option>`. It treats the selected option as the
source of truth, rather than the actual value. This means that if
options are added or removed or their value changes, the `<select>` may
wind up with a different `value` than what's in our model.

This PR resolves this issue by adding a `MutationObserver` to the select
that is used to resync its value to the model whenever the options may
have changed.
2025-11-06 07:49:06 -08:00
Leon Senft
41be02da2f perf(forms): implement change detection for field control bindings
For each field state property, check if it has changed since the last
time it was checked before writing it the corresponding form control
property.

The `pattern` and `required` properties of the field state now return a
default value rather than `undefined` if not defined by metadata.
2025-11-05 00:11:22 +00:00
Matthieu Riegler
15d4bd58d1 fix(forms): interop supports CVAs with signals (#64618)
The directive implemnetation might set CVA values during the template evaluation. Since the template is a reactive context we need to untrack when setting the CVA values to prevent writing to signals in a reactive context.

fixes #64614

PR Close #64618
2025-10-24 09:31:39 +02:00
Miles Malerba
515c2949d8 test(forms): test reactive iteration over array field (#64113)
Adds a test that verifies @for iteration over an array field is actually
reactive to new items being added to the array.

PR Close #64113
2025-10-24 09:29:29 +02:00