976 Commits
Author SHA1 Message Date
Doug Parker 4becefe5c2 refactor(forms): hard-code output schema for signal forms WebMCP tool
Hard-code an explicit `outputSchema` for the implicitly generated signal forms WebMCP tool. This schema accurately describes the simplified success and error object returned by the tool execution, allowing AI agents to confidently interpret the results without hallucination.
2026-11-20 08:35:37 -08:00
Doug Parker f82d8215f9 refactor(forms): simplify signal forms WebMCP tool output structure
Simplify the output structure of the WebMCP tool for signal forms from a verbose array of content blocks to a simple JSON object containing a boolean success flag and an optional array of error strings. This reduces token usage and provides a more semantic output format for AI agents to consume.
2026-11-20 08:35:37 -08:00
Shuaib Hasan Akib 189afa9ce5 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.
2026-11-13 12:10:59 -08:00
rkandleonsenft f9cf82642c fix(forms): apply validator directives to custom form controls
Custom control (`value` or `checked` model, no ControlValueAccessor) bound with NgModel,
FormControlDirective or FormControlName is set up by setupCustomControl, which doesnt call
setUpValidators. Validator directives on element (required, minlength, any directive providing
NG_VALIDATORS) and NG_VALIDATORS provided by control itself never reach FormControl, so control
stays valid and form submits. ControlValueAccessor path merges them, and cleanUpControl already
removes them when FormControlDirective or FormControlName lets go of control

Call setUpValidators from setupCustomControl. Applying validators needs few more changes:

- FormControlName: ɵngControlUpdate runs before ngOnChanges of element, so setting control up
  there would run control's own NG_VALIDATORS before its ngOnInit, and first ngOnChanges of each
  validator directive would emit valueChanges and statusChanges during first change detection.
  ɵngControlUpdate now only resolves control and ngOnChanges sets it up, same as for
  ControlValueAccessor
- required: with FormControlDirective and FormControlName, NgControl also wrote `required` into
  RequiredValidator on same element. That cleared static `required`, and Validators.required
  turned into directive validator that outlived removeValidators(). setInputOnDirectives now
  passes directive to writePredicate and NgControl skips RequiredValidator. Custom control gets
  `required` from enabled RequiredValidator or Validators.required under all three directives
- errors: status inputs are read through untracked getters and `errors` was plain field, so
  re-validation later in same pass (validator directive's ngOnChanges) left `invalid` and `errors`
  stale, and markForCheck during that refresh doesnt re-run view. `errors` is backed by signal now
  like `status`, and ngControlUpdate reads both, so errors-only change is bound in same pass, with
  `emitEvent: false` too
- _enabled on validator directives is backed by signal too, so change from their ngOnChanges
  reaches custom control in same change detection

Fixes #70721

Co-authored-by: leonsenft <[email protected]>
2026-11-11 14:59:21 -08:00
Shuaib Hasan Akib cf37344a4d 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
2026-11-11 14:13:31 -08:00
Shuaib Hasan Akib f499ad0c7c refactor: remove redundant standalone: true from tests
Standalone is the default, so the explicit flag is redundant. Remove the
occurrences added to core, platform-browser, forms and router tests since
the last cleanup.
2026-11-11 12:38:00 -08:00
hawkgs 5a802b5e0f test(forms): replace @mcp-b/webmcp-polyfill with ModelContextMock
Reuse the `ModelContextMock` for the forms tests.
The mock is moved to `packages/private/testing`.
2026-11-11 11:12:58 -08:00
Alex Rickabaugh 7638a3cef6 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.
2026-11-09 16:56:35 -08:00
Matthieu Riegler 4422f4ef50 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
2026-11-09 16:55:19 -08:00
Matthieu Riegler 12278e5f67 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.
2026-11-09 14:18:58 -08:00
Matthieu Riegler e6798fbfd4 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.
2026-11-09 10:51:30 -08:00
Matthieu Riegler 84d332f9c5 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
2026-11-09 10:51:30 -08:00
Максим Иванов 67e5069327 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
2026-11-03 16:28:27 -08:00
Sebastian Barfurth 401b4f2011 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.
2026-11-03 16:20:25 -08:00
KirtiRamchandani 97bde8aa6c 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.
2026-11-02 15:30:22 -08:00
Matthieu Riegler 9e99093bfe 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'`.
2026-10-28 16:45:56 -07:00
Georgi Serev 38afab7a24 refactor(core): use official webmcp-types
Vendor the official `webmcp-types` instead of `@mcp-b/webmcp-types`.
2026-10-28 14:58:48 -07:00
Matthieu Riegler 9bbb7c9d46 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.
2026-10-26 11:38:58 -07:00
Yan Kotliarov 4570715712 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.
2026-10-26 08:32:35 -07:00
Yan Kotliarov 95b9765737 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.
2026-10-26 07:11:46 -07:00
Максим Иванов 0a61a687c4 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.
2026-10-24 13:54:13 -07:00
Shuaib Hasan Akib a7b126925f 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.
2026-10-23 12:34:27 -07:00
jaybell 5d7303aeda 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
2026-10-22 14:17:33 -07:00
jaybell d2f5ec92de 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
2026-10-22 14:17:33 -07:00
arturovt 63f4bd4c7e 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
2026-10-20 13:36:55 -07:00
Doug Parker cdc2ea085e refactor(forms): set WebMCP annotation debugging: false
UI forms are necessarily for end users and not fit for debugging use cases. There might be some developer-only panels which include signal forms where this annotation might be appropriate, but we're keeping it simple for now and can expand if/when such use cases arise.

See: https://groups.google.com/a/chromium.org/g/chrome-ai-dev-preview/c/8tQWCpY6gVA/m/nNy_31okEgAJ
2026-10-20 10:54:46 -07:00
Matthieu Riegler fade609afd refactor(core): modernize unit tests across packages
Removes unnecessary `changeDetection: ChangeDetectionStrategy.Eager` from test components where default `OnPush` change detection works or where state updates can use signals, removes unnecessary `provideZoneChangeDetection()`, replaces `fixture.detectChanges()` with `await fixture.whenStable()` where appropriate, and cleans up redundant `forwardRef`/`CommonModule` imports and unused selectors.
2026-10-14 11:12:55 -07:00
arturovt 6d36d6c097 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.
2026-10-14 10:48:18 -07:00
Shuaib Hasan Akib 6e024600e0 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.
2026-10-14 12:32:38 +02:00
jhjh1214 2a66275511 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.
2026-10-14 12:30:47 +02:00