968 Commits
Author SHA1 Message Date
Shuaib Hasan Akib 818bf54607 fix(forms): format Date min/max for controls with a ControlValueAccessor
When a `[formField]` element also has a ControlValueAccessor, a `Date`
from `minDate()` or `maxDate()` was written to the native `min`/`max`
property with `Date#toString()`, which date inputs ignore. Format it
like the native and custom control paths do.

(cherry picked from commit 189afa9ce5)
2026-11-13 20:11:05 +00:00
Shuaib Hasan Akib 5b66fb4010 fix(forms): flush debounced descendant values when a field is touched
`markAsTouched()` synchronized a pending debounced value only on the
field it was called on. Its descendants were marked as touched, but
their pending values stayed unsynced.

`submit()` marks the root as touched before running the action, so
submitting with Enter while a debounced child still had focus ran the
action with the child's old value. Clicking a submit button hid the bug,
because the click blurs the input first.

This is a regression from #67453. Before it, `submit()` called the
public `markAsTouched()` on each active field, which flushed it.

Flush each field's pending value right after marking it as touched.
Disabled, hidden and readonly fields still aren't marked as touched, but
unlike before #67453 they are flushed too, so their pending value reaches
the model before the action reads it. Below them only fields that already
exist are visited, since a field that was never created can't have a
pending value.

Tested with new specs in `//packages/forms/signals/test/node:test`. The
specs for descendants, `submit()`, an invalid flushed value, a duration
debounce and sibling fields fail without the fix; another checks that
touching a form doesn't create the fields of a hidden subtree.

Fixes #71149

(cherry picked from commit cf37344a4d)
2026-11-11 22:13:36 +00:00
Alex Rickabaugh 935a78ddcb refactor: mark remaining top-level IIFEs as pure
Add `/* @__PURE__ */` annotations to top-level IIFE initializers in `@angular/core`,
`@angular/forms`, and `@angular/platform-browser` so Closure Compiler and bundlers
can drop them when unused.

(cherry picked from commit 7638a3cef6)
2026-11-10 00:56:41 +00:00
Matthieu Riegler 7e16d77e58 perf(forms): avoid retaining AbstractControl in signal forms
Previously, `FieldNodeContext.valueOf` used `result instanceof AbstractControl` to throw `NG1907` when reading an `AbstractControl` inside a regular `form()`. That value reference prevented `AbstractControl` (along with control event classes and validator helpers) from being tree-shaken in applications that only use signal forms.

Introduce an internal symbol-based type guard `ɵisAbstractControl` that checks a private symbol set in `AbstractControl`'s constructor without referencing the `AbstractControl` class value.

Fixes #71621

(cherry picked from commit 4422f4ef50)
2026-11-10 00:55:24 +00:00
Matthieu Riegler 6124529528 fix(forms): preserve options passed to SignalFormControl
Ensure that options passed to SignalFormControl (either as the second argument or as the third argument with a schema or undefined) are preserved and correctly forwarded to compatForm and form().

Previously, normalizeFormArgs relied on args.length === 3, causing options passed as the second argument to be misidentified as a schema function. Furthermore, SignalFormControl only forwarded {injector} to compatForm, discarding options such as name.

(cherry picked from commit 12278e5f67)
2026-11-09 22:19:04 +00:00
Matthieu Riegler a55fb23376 fix(forms): untrack parseErrors read in validator and add unchanged model test
Prevent convertedParseErrors from leaking reactive dependencies into the caller reactive context during synchronous validation runs, and add a test verifying parse errors propagate when model value remains unchanged.

(cherry picked from commit e6798fbfd4)
2026-11-09 18:51:36 +00:00
Matthieu Riegler 67c4e8fc6c fix(forms): prevent duplicate valueChanges events on parseErrors update
This updates NgControl to directly evaluate the parseErrors computed signal inside its dynamic validator, rather than waiting for the effect to update a local variable. This allows synchronous validation updates to pick up the fresh parseErrors immediately during setValue, preventing stale states and duplicate valueChanges emissions when the effect runs later.

It also retains the ability for independent parseErrors changes to correctly update the control's validity silently. Calling `markForCheck()` ensures the view is updated even when `statusChanges` does not emit.

Fixes #71127

(cherry picked from commit 84d332f9c5)
2026-11-09 18:51:36 +00:00
hawkgs fcd82c4326 refactor(core): use official webmcp-types
Vendor the official `webmcp-types` instead of `@mcp-b/webmcp-types`.

Fixes #71268
2026-11-03 16:29:35 -08:00
Максим Иванов 96b027ebf6 perf(forms): avoid creating unused field injectors
Create field injectors only when managed metadata needs an injection
context, and destroy only injectors that have already been created.
Plain metadata and built-in synchronous rules otherwise allocate an
unused injector per field, including during removal.

Preserve eager managed metadata creation, the shared field injection
context, and teardown of asynchronous validators.

Fixes #71623

(cherry picked from commit 67e5069327)
2026-11-03 16:28:33 -08:00
Sebastian Barfurth a7b0e8ef9d fix(forms): support updateOn blur and submit for custom FormValueControl
Custom controls implementing `FormValueControl` bound via `[formControl]` or `formControlName` currently bypass `setUpControlValueAccessor`. In `NgControl.ngControlCreate`, incoming values from the custom control model were applied directly to the `FormControl` without checking `control.updateOn`.

This update respects `control.updateOn` by buffering pending values and dirty state when `updateOn` is set to `'blur'` or `'submit'`. Value and validity are committed on `touch` output emissions for `'blur'`, and on form submission for `'submit'`. Programmatic resets also synchronize the reset value to the custom control when pending changes are cleared.

Programmatic `setValue` and `reset` calls now also update `[(ngModel)]` for custom controls, as they do for CVAs.

(cherry picked from commit 401b4f2011)
2026-11-03 16:20:30 -08:00
KirtiRamchandani 545eb3d07b fix(forms): reflect required validators in compat fields
Expose `required` from `CompatFieldNode` by deriving a signal from the wrapped control's `hasValidator(Validators.required)` state, using the existing control-status signal helper so validator updates and control swaps are observed.

Fixes #68905.

(cherry picked from commit 97bde8aa6c)
2026-11-02 15:30:28 -08:00
Matthieu Riegler 122663145b fix(forms): reject unsupported updateOn in SignalFormControl
Signal forms are model-driven and do not support pending or uncommitted
values. As a result, non-default `updateOn` options (`blur`, `submit`)
cannot be supported.

This commit adds a dev-mode check in `SignalFormControl` to throw an error
when:
1. An unsupported `updateOn` option is passed directly in options to the
   `SignalFormControl` constructor.
2. A non-default `updateOn` option is inherited from a parent `FormGroup`
   or `FormArray` via `setParent()`.

Additionally, `SignalFormControl` explicitly overrides `get updateOn()`
to return `'change'`.

(cherry picked from commit 9e99093bfe)
2026-10-28 16:46:01 -07:00
Matthieu Riegler 8c4e267080 build(docs-infra): move framework API doc generation targets under //adev
Previously, `generate_api_docs(...)` targets lived directly in each
`//packages/**/BUILD.bazel` file (and `render_api_to_html(...)` in
`//tools/manual_api_docs/{blocks,elements}/BUILD.bazel`). Because
`render_api_to_html` validates links against
`//adev/scripts/routes:defined-routes.json`, running wildcard package
builds or tests such as `bazel test //packages/forms/...` pulled in the
`//adev/...` route generation and API manifest dependency graph across
all packages.

Move all framework `generate_api_docs` and manual API `render_api_to_html`
targets into `//adev/src/content/api` alongside `aria`, `cdk`, and `cli`,
leaving only lightweight `files_for_docgen` filegroups in `//packages/...`
and JSON extraction targets in `//tools/manual_api_docs/...`. Remove the
`generate_api_docs` wrapper from `//tools:defaults.bzl` so neither
`//packages/...` nor `//tools/...` loads or depends on `//adev/...`, and
add `//adev/src/content/api:api_docs_test` so `bazel test //adev/...`
explicitly exercises API doc generation and link validation.

(cherry picked from commit 9bbb7c9d46)
2026-10-26 11:39:04 -07:00
Yan Kotliarov be309d5da0 refactor(forms): correct the InputValidityMonitor doc comment
The comment said the service installs a CSS transition and listens
for `transitionstart`. Since it was introduced, the service has
installed `@keyframes` animations and listened for `animationstart`.
Describe what the code does, and rename the private
`createTransitionStyle()` to `createAnimationStyle()` to match.

(cherry picked from commit 4570715712)
2026-10-26 08:32:41 -07:00
Yan Kotliarov 61fe5ca816 test(forms): add missing assertions to two signal forms specs
The `debounced()` cycle-error spec had no expectations, and it ended
before the debounced load started, because `debounced()` registers no
pending task. Check the loads and the field's pending and valid state
across the debounce.

The `validateAsync` orphan spec registered abort listeners but never
checked them. Check that removing an item aborts its in-flight load
and leaves the other item's load running.

(cherry picked from commit 95b9765737)
2026-10-26 07:11:50 -07:00
Максим Иванов a02ad167dc perf(forms): match multi-select identities in a single pass
Avoid repeated option scans when a multi-select receives multiple values
with the default identity comparison. Match registered options against a
Set of requested values and retain the first match for duplicate options.

Keep signed zero distinct, ignore sparse-array holes, and preserve custom
comparator invocation order. Apply all selection writes synchronously and
cover option setters, removal, duplicate identities, and model updates.

(cherry picked from commit 0a61a687c4)
2026-10-24 13:54:18 -07:00
Shuaib Hasan Akib 1c7a906d4a docs(forms): update stale statements in the signal forms API docs
- PACKAGE.md: debouncing is supported through the `debounce()` rule, so
  remove it from the list of unsupported features.
- Use the `{when}` form of `disabled()` in JSDoc examples instead of the
  deprecated function overload.

(cherry picked from commit a7b126925f)
2026-10-23 12:34:31 -07:00
jaybell 6a41c9920c test(forms): assert this: void on destructured field context helpers
Replace the runtime-only test with one that also checks
`ThisParameterType` of `valueOf`, `stateOf` and `fieldTreeOf`, so the
test fails to compile if the `this: void` annotation regresses.

Claude-Session: https://claude.ai/code/session_011r2XWZik3FoTLYtMWjWr8P
(cherry picked from commit 5d7303aeda)
2026-10-22 14:17:39 -07:00
jaybell 1586cc72ab fix(forms): annotate field context helpers with this: void
`valueOf`, `stateOf` and `fieldTreeOf` on the field context are commonly
destructured in logic functions (e.g. `({valueOf}) => valueOf(p.name)`).
Because they were declared with method syntax, `@typescript-eslint/unbound-method`
and oxlint's `typescript/unbound-method` reported a false positive for every
destructured use.

At runtime these members are already safe to destructure: `FieldNodeContext`
binds `stateOf` and `fieldTreeOf` in its constructor and defines `valueOf` as
an arrow function. Declaring `this: void` makes the public types match that
contract. This is a type-only change with no runtime behavior change.

Claude-Session: https://claude.ai/code/session_01VjkGFtQxxE6pd2BoC8wRxh
(cherry picked from commit d2f5ec92de)
2026-10-22 14:17:38 -07:00
arturovt 41b189752e fix(forms): don't crash when formControlName has no matching control
Even tho reactive forms might be considered legacy now, this fix covers
a real production case.

Prior to this commit, a `formControlName` with no control for it in the
form group crashed in production with a raw `TypeError: Cannot read
properties of null (reading '_rawValidators')`. The error said nothing
about forms or which control was missing, so it was hard to trace back
to the template. A common way to hit it: the template and the form group
are built from the same list but with two different filters, so an item
passes the template's filter but was never given a control.

`AbstractFormDirective.addControl` read `this.form.get(dir.path)` and
passed the result into `_setupWithForm` without a null check. In dev
mode this was still caught earlier, in `setUpControlValueAccessor`
("Cannot find control with path"). In production `ngDevMode` strips that
check away, so the null control reached `setUpValidators`, which
dereferences it right away and threw the bare `TypeError`.

With this fix, `addControl` checks the control first and throws a coded
`RuntimeError` (NG01055), with a docs page on angular.dev. The check is
not gated behind `ngDevMode`, since the crash it prevents is a production
one. The message stays `ngDevMode`-only and lists the sibling controls
that exist at that path, which is usually enough to spot a name mismatch.

Fixes #71155

(cherry picked from commit 63f4bd4c7e)
2026-10-20 20:37:02 +00:00
arturovt cc515b8b23 perf(forms): use addEventListener to avoid unconditional CD scheduling on blur
Previously, the blur and input listeners in nativeControlCreate were
registered via host.listenToDom(), which routes through wrapListener and
calls markViewDirty before running the callback. This caused
scheduler.notify() to fire on every blur event, even when the control was
already touched and the signal write was a no-op.

Switch to native addEventListener so that change detection ticks are only
triggered by actual signal changes. Remove the now-unused listenToDom
method from ControlDirectiveHost and its implementation.

(cherry picked from commit 6d36d6c097)
2026-10-14 17:48:24 +00:00
Shuaib Hasan Akib dcb29a9fb0 docs: fix @param names that don't match their parameters
The API reference only attaches a `@param` description to a parameter
when the names match. Several APIs documented parameters under a
different name than the one in the signature, so angular.dev rendered
those parameters with an empty description.

Update the JSDoc to use the actual parameter names:

- core: `ViewContainerRef.move()` documented `index` instead of
  `currentIndex`.
- core: `inject()` still documented the `flags` parameter, which was
  replaced by `options` when `InjectFlags` was removed from the public
  API. Use the same description as the other `inject()` overloads.
- core: `twoWayBinding()` documented `eventName` instead of `publicName`.
- common: `Location.subscribe()` documented `value` and `exception`
  instead of the `onNext` and `onThrow` callbacks, and didn't document
  `onReturn`.
- common/upgrade: `UrlCodec.encodeSearch()`, `decodeSearch()`,
  `encodeHash()` and `decodeHash()` documented `path` instead of
  `search` or `hash`, and the first `normalize()` overload documented
  `path` instead of `href`. Also fix a "has string" typo.
- router: `DefaultTitleStrategy.updateTitle()` documented a `title`
  parameter instead of `snapshot`. Also update its description, since
  it builds the title from the router state rather than setting a
  given value.
- forms: `minDate()` and `maxDate()` documented `minDate` and `maxDate`
  instead of `minDateValue` and `maxDateValue`.

Verified by rebuilding the docs with `//adev:build` and checking that
each of these parameters now has a description in the generated API
reference pages, and that no other `@param` name mismatches remain
besides `IterableChanges.forEachOperation` (which documents its
callback's arguments) and the `QueryList` constructor.

(cherry picked from commit 6e024600e0)
2026-10-14 12:32:46 +02:00
jhjh1214 276248ff3d docs(forms): document that minDate and maxDate expect UTC dates
A date input reads and writes `Date` values at midnight UTC, which is how
`valueAsDate` behaves. `minDate` and `maxDate` compare against that value
and format the `min` and `max` attributes with UTC getters, so a limit built
from local time (`new Date(2026, 5, 1)` or `new Date()`) is shifted by the
user's UTC offset. Depending on the time zone, the limit date itself is
rejected or the attribute is a day off.

Add a `minDate() and maxDate()` section to the validation guide, which had
none, and note the UTC contract in the JSDoc of `minDate` and `maxDate`.
Point the `@see` links of those two functions at the new section.

(cherry picked from commit 2a66275511)
2026-10-14 12:30:57 +02:00
Shuaib Hasan Akib 26279ed4f1 test(forms): cover the deprecated disabled signatures
`hidden()` and `readonly()` have tests for their deprecated function
syntax, but `disabled()` had none for passing a function or a string
directly. Add a spec for each.

Tested with `//packages/forms/signals/test/node:test`. Both specs fail
if `disabled()` ignores a function or string passed directly.

(cherry picked from commit f416f7e248)
2026-10-12 23:06:54 +00:00
Shuaib Hasan Akib 206f541d59 docs(forms): use the when option in disabled examples
Passing a function or string directly to `disabled()` is deprecated in
favor of `{when: ...}`. The `SchemaFn` API example, the schemas guide
diagram and an internal comment still showed the deprecated form.

Built with `//adev:build`.

(cherry picked from commit b6116ea029)
2026-10-12 23:06:54 +00:00
Kam db91010128 fix(docs-infra): stop generating member anchors that do not exist
When `{@link Foo}` does not resolve, the renderer falls back to
`CurrentSymbol.Foo` without checking that `Foo` is a member of the symbol being
rendered, so it emits a URL to an anchor that does not exist. `DefaultExport` is
rendered in both core and router while `injectAsync` is only in core's entries,
so /api/router/DefaultExport links `injectAsync` to
/api/router/DefaultExport#injectAsync.

Resolve the symbol first, and only fall back to the member form when the symbol
really is a member. A property on a function entry, and an initializer API
function, no longer take a fragment at all. Make the `@see` on `DefaultExport`
an absolute link so it resolves from every package that renders it.

Two consequences worth calling out. A `{@link}` that resolves to nothing now
fails the docs build where it used to emit a broken anchor, including a
core-only symbol referenced from a type another package re-exports. And an
explicit `{@link}` no longer consults the auto-linking exemption list, which is
what lets `{@link Event}` on `RouterEvent` reach /api/router/Event instead of a
fragment on itself.

(cherry picked from commit c863e00246)
2026-10-07 01:29:40 +00:00
leonsenft c91a8c429d fix(forms): use Object.is when comparing control bindings in signal forms
`bindingUpdated` previously used `!==` to check whether a control binding
value changed since the last update pass. Because `NaN !== NaN` is `true`,
any numeric field with a `NaN` value re-wrote its value to the control on
every change detection cycle (resetting native `<input>` elements to `''`).

(cherry picked from commit e118e15527)
2026-10-06 23:42:52 +00:00
arturovt b0710b8db6 fix(forms): don't crash when control is missing in setUpValidators
setUpValidators was reading control._rawValidators without checking
whether control even exists. If a directive's ngOnChanges fires
before its control is wired up (this can happen in some race
conditions), control is null or undefined, and it throws a raw
TypeError that doesn't tell you anything useful.

Added a check at the top: if control is null or undefined, throw a
proper RuntimeError (code 1003) instead. The check itself is always
on, not gated by ngDevMode, since the whole point is that this
happens in production builds, where the existing ngDevMode-only
guards get stripped out. The message text is still gated behind
ngDevMode though, the same way MISSING_CONTROL_VALUE (-1002) does.

Added a test that reproduces this with a real `@Component` using
[formGroup], where the form input is never set, so it goes through
Angular's actual change detection and lifecycle hooks instead of
just calling the function directly.

(cherry picked from commit fc3dc890aa)
2026-10-06 16:59:01 +00:00
Shuaib Hasan Akib 6a96a40031 refactor(forms): modernize value accessor integration tests
Migrate the value accessor integration spec to current Angular patterns:
- use standalone fixtures that import only the forms module they need,
  instead of declaring them through an `initTest` helper
- replace `*ngFor`/`*ngIf` with `@for`/`@if`
- use `inject()` instead of constructor injection

The reactive and template integration specs reuse two of these fixtures and
are updated to create them directly.

(cherry picked from commit de47371baf)
2026-10-05 16:09:38 +00:00
lazerg ef0359676c fix(forms): skip class bindings for orphaned fields
The class bindings from `provideSignalFormsConfig` run in an `afterRenderEffect`, which keeps running while its view is detached. If an array is replaced in the meantime, the detached `@for` still holds the old rows and computing their classes throws NG01904. Skip the class updates while the field is orphaned.

Fixes #70934

(cherry picked from commit c0dc8c4bbe)
2026-10-02 18:57:00 +00:00