Commit graph

742 commits

Author SHA1 Message Date
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
Matthieu Riegler
b885851cbe build: don't substitute binary files
Previously, ng_package applied version stamping to all source files, which corrupted binary files like SQLite databases.

This change ignores text substitution for files passed to the `data` attribute, ensuring binary assets are preserved intact in the final package.

fixes #66637
2026-01-21 10:35:04 -08:00
Leon Senft
d0ba332292 refactor(forms): remove unused API
Remove `SubmittedStatus` which is no longer used.
2026-01-20 10:19:58 -08:00
Shuaib Hasan Akib
4adbc4fa19 refactor(forms): update Reactive Forms guide URL
Updates the Reactive Forms documentation link to the new `guide/forms/reactive-forms` path after the recent docs restructure.
2026-01-20 10:11:48 -08: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
e7b2dde6d1 fix(forms): fix control value syncing on touch
Previously we were unconditionally setting the control value back into
the value, regardless of if it had actually been changed. This PR
changes the logic to flush the pending sync on touch if there is one, or
just skip it if there isn't.
2026-01-16 09:25: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
cexbrayat
7fd076bdd3 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.
2026-01-12 13:48:16 -08:00
Shuaib Hasan Akib
1b4dcc01ff docs: replace old https://angular.io/license with https://angular.dev/license 2026-01-12 13:41:30 -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
SkyZeroZx
f4469ad583 refactor(core): update error message links to versioned docs (#66374)
Error message links now point to the archived documentation site (v*.angular.dev)
so that referenced content matches the framework version in use.

See angular#44650

PR Close #66374
2026-01-09 22:33:51 +00: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
kirjs
7d985ce08e docs(forms): Clarify returning errors from submit functions
Update outdate comment, and add a section to the docs
2026-01-09 08:47:42 -08:00
Leon Senft
46dbd18566 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`.
2026-01-07 15:07:30 -05:00
SkyZeroZx
b2f417585a docs: update angular.io links to angular.dev in comments, TSDoc, and warnings 2026-01-07 14:12:15 -05:00
SkyZeroZx
e7d99f02cb 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.
2026-01-07 14:07:25 -05: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
Shuaib Hasan Akib
b93d5ec27a 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.
2026-01-06 10:34:46 -05:00
Shuaib Hasan Akib
456ca35906 docs(forms): fix duplicate validator reference titles in AbstractControl
The removeValidators and hasValidator methods both had identical "Reference to a ValidatorFn" section titles, causing duplicate entries in the API documentation table of contents.
2026-01-05 19:26:31 -05:00
Charles Lyding
ab0fb1633c build(forms): setup infrastructure for code examples
This commit introduces the infrastructure for embedding code examples within Angular packages, enabling them to be consumed by the Angular CLI's MCP server.

The `@angular/forms` package is the first to adopt this new feature. A new `ng_examples_db` Bazel rule is used to build a SQLite database from markdown files containing code examples. This database is then included in the published npm package.

The `package.json` for `@angular/forms` has been updated with an `angular.examples` field to allow tooling to discover and use the code examples.
2026-01-05 12:36:00 -05:00
SkyZeroZx
b735c45974 docs: update tsDoc code examples to use TypeScript syntax highlighting 2026-01-05 12:31:44 -05:00
SkyZeroZx
b1a0d1d8e2 docs: Add form control state management and event options 2026-01-05 12:16:09 -05:00
Shuaib Hasan Akib
e3781cd88a docs: fix incorrect FormArray example link
Update the typed forms guide link to point to the correct
FormArray section instead of the FormControl getting started example.
2026-01-02 08:28:17 +01:00
kirjs
282220d032 fix(forms): Support readonly arrays in signal forms
This would allow using `readonly Array<...>` in types
2026-01-02 08:26:06 +01:00
SkyZeroZx
398078f456 refactor(forms): add MANAGED_METADATA_LAZY_CREATION runtime error
Add the `MANAGED_METADATA_LAZY_CREATION` `RuntimeError`  in signal form,
making it tree-shakeable.
2026-01-02 08:17:39 +01:00
Shuaib Hasan Akib
abb179466d 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.
2026-01-02 08:13:40 +01: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
Miles Malerba
244b54c9bf 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.
2025-12-17 15:42:07 -08: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
Kirill Cherkashin
193aa332fc
docs(forms): improve JSDoc for Signal Forms Schema types
Improved documentation for Schema, SchemaFn, and SchemaOrSchemaFn types
with clearer descriptions and usage examples.
2025-12-15 14:02:35 -08:00
Matthieu Riegler
44d4439bc4 refactor(forms): add signal forms to the type tests
This will ensure that signal forms emit valid typings.
Also this commits moves `@standard-schema/spec` from peer-dep to regular dep
2025-12-15 11:44:54 -08:00
kirjs
3a01d72850 refactor(forms): convert Signal Forms errors to use RuntimeError
- Added 13 new error codes to forms/src/errors.ts (1900-1999)
- use RuntimeError
2025-12-15 11:44:02 -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
Miles Malerba
d0097f7d0c fix(forms): fix signal forms type error
Removes the `implements` clause on the `Field` directive since it is
causing type errors for people.
2025-12-11 15:33:12 -08:00
Matthieu Riegler
14713d0992 fix(forms): allow resetting with empty string
Both empty string and null values should be accepted when resetting

fixes #65949
2025-12-10 10:04:54 -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