131 Commits

Author SHA1 Message Date
Matthieu Riegler 82d556a8fb 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

(cherry picked from commit 65fa5b5439)
2026-01-12 21:49:23 +00:00
cexbrayat 5cbb66fdf2 test(forms): improve test coverage for multiple pattern validators
Add comprehensive test cases to validate behavior when multiple
pattern validators are applied to the same field.

These tests clarify that multiple patterns operate with AND logic,
where each pattern is validated independently and produces its own
error when it doesn't match.

(cherry picked from commit 7fd076bdd3)
2026-01-12 21:48:19 +00:00
Miles Malerba 0055f3cc79 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]`

(cherry picked from commit 5671f2cc07)
2026-01-09 22:33:13 +00:00
kirjs 24fa4a2460 docs(forms): Clarify returning errors from submit functions
Update outdate comment, and add a section to the docs

(cherry picked from commit 7d985ce08e)
2026-01-09 16:47:46 +00:00
Leon Senft ff531752b0 refactor(forms): remove customError()
Remove the `customError` function and `CustomValidationError` type.

These were made obsolete by support for returning plain object literals
as custom errors.

This also catches few `field` properties that were missed in the
renaming to `fieldTree`.

(cherry picked from commit 46dbd18566)
2026-01-07 15:07:35 -05:00
SkyZeroZx ae1dc16bb0 fix(forms): clean up abort listener after timeout
Removes the abort event listener once the debounce timeout completes.

This avoids lingering listeners, prevents potential memory leaks, and ensures
the abort logic runs at most once.

(cherry picked from commit e7d99f02cb)
2026-01-07 14:07:28 -05:00
Miles Malerba e3fba182f9 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

(cherry picked from commit 2d85ae5811)
2026-01-06 17:21:09 -05:00
Leon Senft af1d4acb9d 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`.

(cherry picked from commit 82a2de201f)
2026-01-06 13:12:21 -05:00
Leon Senft 0e8b9d8cde 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`.

(cherry picked from commit 15bddbdcda)
2026-01-06 13:12:21 -05:00
Leon Senft ff37a13913 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.

(cherry picked from commit 0c8f15d546)
2026-01-06 13:12:21 -05:00
Leon Senft a4ba820d36 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

(cherry picked from commit c149f47ef6)
2026-01-06 13:12:21 -05:00
Shuaib Hasan Akib 45bfd824bf docs(forms): add documentation links to Signal Forms API
Add @see JSDoc tags to Signal Forms API functions and classes to link to the essentials guide and detailed documentation pages. This improves discoverability of Signal Forms documentation from the API reference.

(cherry picked from commit b93d5ec27a)
2026-01-06 10:34:49 -05:00
SkyZeroZx 6cfbc736b4 docs: update tsDoc code examples to use TypeScript syntax highlighting
(cherry picked from commit b735c45974)
2026-01-05 12:31:47 -05:00
kirjs 6bd22df987 fix(forms): Support readonly arrays in signal forms
This would allow using `readonly Array<...>` in types

(cherry picked from commit 282220d032)
2026-01-02 08:26:09 +01:00
SkyZeroZx b37f46b652 refactor(forms): add MANAGED_METADATA_LAZY_CREATION runtime error
Add the `MANAGED_METADATA_LAZY_CREATION` `RuntimeError`  in signal form,
making it tree-shakeable.

(cherry picked from commit 398078f456)
2026-01-02 08:17:43 +01:00
Shuaib Hasan Akib b9d7455d9c refactor(core): mark VERSION exports as pure for better tree-shaking
Adds a PURE annotation to VERSION constants, enabling tree-shaking
and keeping the implementation consistent with other pure exports.

(cherry picked from commit abb179466d)
2026-01-02 08:13:44 +01:00
Leon Senft 85621f11e1 test(forms): add test coverage for binding errors to custon controls
This input was missing dedicated test coverage.

(cherry picked from commit e7745dc9dd)
2026-01-02 08:09:39 +01:00
Leon Senft 6d167bd64c test(forms): remove duplicate test case
We had two test cases that tested the `Field` directive synchronizes
with a custom checkbox control components.

(cherry picked from commit 8832fc01b2)
2026-01-02 08:09:39 +01:00
Leon Senft ec110f170b 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

(cherry picked from commit 1a4c3eb1d0)
2026-01-02 08:09:39 +01:00
Leon Senft 79d16919a5 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.

(cherry picked from commit 9ad603fa11)
2026-01-02 08:09:39 +01:00
Leon Senft 8c83266816 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

(cherry picked from commit 4f73a350a5)
2026-01-02 08:09:39 +01:00
Leon Senft 561772b152 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

(cherry picked from commit 89c37f1f7f)
2026-01-02 08:09:39 +01:00
Leon Senft 929306e658 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

(cherry picked from commit b563b5cfc2)
2026-01-02 08:09:39 +01:00
Leon Senft f0fb1d8581 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

(cherry picked from commit 82edf18427)
2026-01-02 08:09:38 +01:00
Leon Senft 9748b0d5da 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

(cherry picked from commit cb09fb8308)
2026-01-02 08:09:07 +01:00
Miles Malerba 59b3790031 refactor(forms): rename server errors to submission errors
This better reflects the intent to indicate an error during submission,
regardless of whether the error came from the server or not.

(cherry picked from commit 244b54c9bf)
2025-12-17 15:42:11 -08:00
Matthieu Riegler feed89e83c ci: reformat files
This is after we've slightly changed a rule in #66056

(cherry picked from commit 6270bba056)
2025-12-16 14:44:25 -08:00
Miles Malerba 729b96476b refactor(forms): rename field to fieldTree in FieldContext and ValidationError
BREAKING CHANGE:

(cherry picked from commit ae0c59028a)
2025-12-16 10:26:26 -08:00
Kirill Cherkashin 5afb1eb600 docs(forms): improve JSDoc for Signal Forms Schema types
Improved documentation for Schema, SchemaFn, and SchemaOrSchemaFn types
with clearer descriptions and usage examples.

(cherry picked from commit 193aa332fc)
2025-12-15 14:02:39 -08:00
kirjs 45e967b295 refactor(forms): convert Signal Forms errors to use RuntimeError
- Added 13 new error codes to forms/src/errors.ts (1900-1999)
- use RuntimeError

(cherry picked from commit 3a01d72850)
2025-12-15 11:44:06 -08:00
Miles Malerba 81772b420d 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()
  }
})
```

(cherry picked from commit 348f149e8b)
2025-12-12 08:07:57 -08:00
Miles Malerba 4fd2b722b4 fix(forms): fix signal forms type error
Removes the `implements` clause on the `Field` directive since it is
causing type errors for people.

(cherry picked from commit d0097f7d0c)
2025-12-11 15:33:17 -08:00
Matthieu Riegler cbb10179c8 fix(forms): allow resetting with empty string
Both empty string and null values should be accepted when resetting

fixes #65949

(cherry picked from commit 14713d0992)
2025-12-10 10:04:58 -08:00
kirjs 6d7475582f fix(forms): Reuse key in parent in compat structure
This fixes the "Compat nodes do not use keyInParent." error when trying to bind compatField.

(cherry picked from commit 179b4cba67)
2025-12-09 12:59:27 -08:00
Miles Malerba f254ff4f2e feat(forms): expose element on signal forms Field directive
This allows for easier focusing of the relevant element based on the
`field` property of a `ValidationError`

(cherry picked from commit aff8b248b3)
2025-12-09 09:47:56 -08:00
Miles Malerba 5880fbc73c feat(forms): redo the signal forms metadata API
This PR makes a number of changes to the metadata API to address design
flaws in the previous API. Some of the changes include:

- Replaces the previous `MetadataKey` and `AggregateMetadataKey` with a
  single unified `MetadataKey` that is used for all metadata.
- The new `MetadataKey` is only defined for fields that explicitly set
  it in their schema logic
- All metadata now has reducer / aggregate behavior
- The new `MetadataKey` has an option to create a managed key which
  wraps the result of its computed aggregate into some other structure
  such as a `Resource` or `linkedSignal`
- There are now two APIs to create metadata keys
  - `createMetadataKey` for pure computed metadata
  - `createManagedMetadataKey` for metadata that manages its computation
    internally

(cherry picked from commit ebc5c2b083)
2025-12-09 09:21:45 -08:00
cexbrayat 55fc677cef 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

(cherry picked from commit 9fe9566581)
2025-12-08 10:30:48 -08:00
Anuj Chhajed 288238abef refactor(core): correct all typeof ngDevMode comparison patterns introduced by #63875
This change replaces all remaining occurrences of `typeof ngDevMode !== undefined`
with the correct `typeof ngDevMode !== 'undefined'` form. This aligns the codebase
with JavaScript typeof semantics and maintains consistency with other Angular code.

(cherry picked from commit 96b79fc393)
2025-12-08 10:30:06 -08:00
Miles Malerba a4c436a058 refactor: followup cleanup for #65758 fallout
Fixes some issues left behind by recent refactor

(cherry picked from commit efde94a525)
2025-12-08 10:28:04 -08:00
Kirill Cherkashin 7de8558219 refactor(forms): Break logic.ts into separate files
This would make it easier to navigate

(cherry picked from commit 5be33048cc)
2025-12-04 11:33:26 -08:00
Alex Rickabaugh bf1c12cd93 fix(forms): memoize reads of child fields in signal forms (#65802)
Previously, navigating a `FieldTree` in signal forms involved reactive reads
of the value of the parent field(s), both directly and via `.childrenMap()`.

This meant that on _any_ change to the value of a field, reactive
notifications would trigger updates of computeds, reruns of effects, etc.
So for example, this effect would run on every change to the form:

```ts
const f = form(signal({data: 'abc', unrelated: 0}));
effect(() => {
  // accessing f.data incurs a dependency on f().value() which changes
  // on every change in the whole form
  console.log(f.data().value());
});
```

This is deeply counterintuitive and troublesome when attempting to write
effect logic, and also results in `computed`s unnecessarily updating.

This change introduces the concept of a "reader" computed, which memoizes
the access of a field at a given key via the reactive graph. With this, the
same `f.data` access above now depends on the `data` reader in `f` only,
which is effectively a constant computed. As a result, the effect only
reruns on changes to `data`'s value, as intended.

PR Close #65802
2025-12-03 12:52:43 -08:00
Alex Rickabaugh 2c12661620 refactor(forms): simplify child field creation (#65802)
Previously, several values were being passed into the creation of
`FieldNodeStructure`s that were only used in the creation of child nodes.
Separately, we also passed a `createChildNode` function which these values
were passed back into.

Instead, this moves the small bit of logic from structure.ts behind the
`createChildNode` callback, which reduces the passing of values back-and-
forth and gives `createChildNode` a much more suitable signature.

PR Close #65802
2025-12-03 12:52:43 -08:00
SkyZeroZx 6b4ab876e8 feat(forms): Allows transforms on FormUiControl signals
Extends the `FormUiControl` interface to allow `InputSignalWithTransform` in addition to `InputSignal` for its properties.

Fixes #65756

(cherry picked from commit 7d1e502345)
2025-12-03 15:13:06 +01:00
Leon Senft 609699ae17 perf(core): tree shake unused dynamic [field] binding instructions (#65599)
Move the instructions used to dynamically bind a `Field` directive to a
form control onto the `Field` itself. This way the instructions are only
retained if the app uses the `Field` directive.

PR Close #65599
2025-12-03 15:10:50 +01:00
Leon Senft a5dbd4b382 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 017672f742 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

(cherry picked from commit f35b2ef47c)
2025-12-02 12:59:53 +01:00
Matthieu Riegler 8e0df4083d docs(docs-infra): Show examples on function overloads
(cherry picked from commit a784995a98)
2025-12-02 12:13:16 +01:00
kirjs e3f5f34732 refactor(forms): Make reset take value
Now you can do form.reset({name: 'cat', age: 4});

(cherry picked from commit dec222d4d7)
2025-11-25 10:51:38 -05:00
Miles Malerba 7d5c7cf99a 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.

(cherry picked from commit c70e246c23)
2025-11-25 10:33:41 -05:00
Leon Senft 8acf5d2756 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.

(cherry picked from commit 3a1eb07c46)
2025-11-25 09:16:01 -05:00