Commit graph

597 commits

Author SHA1 Message Date
Matthieu Riegler
c0d88c37c9 fix(forms): Emit FormResetEvent when resetting control (#64024)
Prior to this change, the event was emitted by the Form Directive. With the change, it is now emitted at the control level.

fixes #58894

PR Close #64024
2025-09-24 16:48:32 +00:00
Matthieu Riegler
3d1e8fa08b docs: add types category for signal forms API entries (#63967)
PR Close #63967
2025-09-22 22:47:38 +00:00
Kristiyan Kostadinov
f5b50ec20d refactor: clean up explicit standalone flags from tests (#63963)
Since standalone is the default, we can dropn the `standalone: true` flags from our tests.

PR Close #63963
2025-09-22 14:27:34 +00:00
Matthieu Riegler
c50d659509 refactor(core): protect InjectionToken usage of ngDevMode (#63875)
Since those are top level APIs, `ngDevMode` might not be available at runtime if they're invoked before the variable is set.

fixes #62796

PR Close #63875
2025-09-19 21:27:45 +00:00
Matthieu Riegler
e835c359f7 docs: Add categories to form apis (#63938)
PR Close #63938
2025-09-19 20:21:16 +00:00
kirjs
b60d5e49b1 refactor(forms): get rid of watFor in validation status spec (#63948)
It was flaky, and now it is not flaky

PR Close #63948
2025-09-19 17:59:32 +00:00
Jessica Janiuk
db8f716a0e Revert "docs: Add categories to form apis (#63938)" (#63950)
This reverts commit 0c4feb8e9e.

PR Close #63950
2025-09-19 17:58:10 +00:00
Matthieu Riegler
0c4feb8e9e docs: Add categories to form apis (#63938)
PR Close #63938
2025-09-19 17:02:57 +00:00
SkyZeroZx
d201cd2c2b feat(forms): Prevents marking fields as touched/dirty when state is hidden/readonly/disabled (#63633)
Ensures fields that are hidden, disabled, or readonly cannot be marked as touched or dirty, improving form state integrity

PR Close #63633
2025-09-15 16:52:15 +00:00
Andrew Scott
c3576506b3 refactor(core): Update tests for zoneless by default (#63668)
This updates tests and examples only to prepare for zoneless by default.

These changes were identified and made as part of #63382. Anything that
failed gets `provideZoneChangeDetection` unless the fixes were easily
and quickly determined.

It also adds the zoneless provider to the `initTestEnvironment` calls
for tests in this repo to prevent regressions before #63382 is merged.

PR Close #63668
2025-09-09 14:41:56 -07:00
Miles Malerba
00a1806eaa refactor(forms): add validateStandardSchema to public api (#63616)
Add `validateStandardSchema` which was accidentally omitted from the
public api.

PR Close #63616
2025-09-08 13:58:55 -07:00
Miles Malerba
1233f7319d refactor(forms): move control directive under api (#63616)
Moves the control directive under api/ since it is part of the public
API. Also removes the interop abstract control from the public API

PR Close #63616
2025-09-08 13:58:55 -07:00
Miles Malerba
6d3f6542b4 refactor(forms): mark all signal forms apis as experimental (#63616)
Ensure that each public API symbol in @angular/forms/signals is marked
as `@experimental`

PR Close #63616
2025-09-08 13:58:55 -07:00
Miles Malerba
bacda4f41b refactor(forms): add support for binding number fields to date inputs (#63585)
In addition to `value` and `valueAsDate`, the date type fields work with
`valueAsNumber` as well, treating it as epoch miliseconds.

PR Close #63585
2025-09-05 14:00:34 -07:00
Miles Malerba
681b13c40f refactor(forms): add support for more input types (#63585)
Adds additional handling for input types that handle numbers:
- number
- range
- datetime-local

As well as input types that handle dates:
- date
- month
- week
- time
- *not* datetime-local which does not allow setting valueAsDate

This PR allows binding either a `Field<string>` or `Field<number>` to
the number type inputs and a `Field<string>`, `Field<numebr>`, or
`Field<Date | null>` to the date type inputs. Binding uses the
corresponding `.value`, `.valueAsNumber`, or `.valueAsDate` according to
the type of the `Field`.

When reading new values out of the input, the `Control` directive will
read the property that aligns with the type of the existing value in the
`Field` and write back the same type.

PR Close #63585
2025-09-05 14:00:34 -07:00
Miles Malerba
db95a5c763 refactor(forms): loosen the error and disabled type on FormUiControl (#63455)
This allows passing errors and disabled reasons that did not originate
from `@angular/forms/signals` in case the the control is being used
separately from the forms system

PR Close #63455
2025-08-29 14:44:13 -07:00
Miles Malerba
10ef96adb3 fix(forms): consistent treatment of empty (#63456)
Removes custom handling of emptiness in several of the validators and
replaces it with a common `isEmpty` check. The common empty check
considered the following values to be empty: `null`, `undefined`, `''`,
`false`, `NaN`

Generally most validators should treat an empty value as valid. This
aligns with both the behavior or native HTML validators and reactive
forms validators.

As an example, consider an optional email field. If the email validator
considered empty string to be an invalid email, there would be no way
for the user to not enter it.

There are several exceptions to this rule:
- `required` whose entire purpose is to ensure that the field is *not*
  empty
- `validateStandardSchema` which should subject all values including
  empty ones to the specified standard schema. It is up to the schema to
  decide whether an empty value is valid or not
- `validate`/`validateAsync` which leaves it up to the user's custom
  validation logic to decide if an empty value is valid.

PR Close #63456
2025-08-29 14:43:03 -07:00
Miles Malerba
862495c238 build: configure signal forms for release (#63458)
Configures signal forms to release as `@angular/forms/signals`

PR Close #63458
2025-08-29 14:31:35 -07:00
Matthieu Riegler
2f5f975cb5 refactor(forms): fix dependencies (#63451)
common/http was missing

PR Close #63451
2025-08-28 09:43:39 -07:00
Hongxu Xu
1f4c5f72aa refactor(bazel): reduce build deps (#63348)
clean up deps in bazel build scripts

PR Close #63348
2025-08-28 09:16:10 -07:00
Miles Malerba
b8314bd340 feat(forms): add experimental signal-based forms (#63408)
This commit introduces an experimental version of a new signal-based forms API for Angular. This new API aims to explore how signals can be leveraged to create a more declarative, intuitive, and reactive way of handling forms.

The primary goals of this new signal-based approach are:

*   **Signal-centric Design:** Place signals at the core of the forms experience, enabling a truly reactive programming model for form state and logic.
*   **Declarative Logic:** Allow developers to define form behavior, such as validation and conditional fields, declaratively using TypeScript. This moves logic out of the template and into a typed, testable schema.
*   **Developer-Owned Data Model:** The library does not maintain a copy of data in a form model, but instead read and write it via a developer-provided `WritableSignal`, eliminating the need for applications to synchronize their data with the form system.
*   **Interoperability:** A key design goal is seamless interoperability with existing reactive forms, allowing for incremental adoption.
*   **Bridging Template and Reactive Forms:** This exploration hopes to close the gap between template and reactive forms, offering a unified and more powerful approach that combines the best aspects of both.

This initial version of the experimental API includes the core building blocks, such as the `form()` function, `Field` and `FieldState` objects, and a `[control]` directive for binding to UI elements. It also introduces a schema-based system for defining validation, conditional logic, and other form behaviors.

Note: This is an early, experimental API. It is not yet complete and is subject to change based on feedback and further exploration.

Co-authored-by: Kirill Cherkashin <kirts@google.com>
Co-authored-by: Alex Rickabaugh <alxhub@users.noreply.github.com>
Co-authored-by: Leon Senft <leonsenft@users.noreply.github.com>
Co-authored-by: Dylan Hunn <dylhunn@gmail.com>
Co-authored-by: Michael Small <michael-small@users.noreply.github.com>

PR Close #63408
2025-08-28 09:02:43 -07:00
Joey Perrott
2fcafb65c5 build: rename defaults2.bzl to defaults.bzl (#63383)
Use defaults.bzl for the common macros

PR Close #63383
2025-08-25 15:45:01 -07:00
Matthieu Riegler
0dd95c503f feat(forms): Add FormArrayDirective (#55880)
The `FormArrayDirective` will allow to have a `FormArray` as a top-level form object.

* `NgControlStatusGroup` directive will be applied to the `FormArrayDirective`
* `NgForm` will still create a `FormGroup`

Fixes angular#30264

BREAKING CHANGE: This new directive will conflict with existing FormArray directives or formArray inputs on the same element.

PR Close #55880
2025-08-21 09:38:37 -07:00
Matthieu Riegler
318718ce64 refactor(forms): extract shared logic from FormGroupDirective (#55880)
Ahead of the implementation of `FormArrayDirective`, extract the shared logic into an abstract class.

PR Close #55880
2025-08-21 09:38:37 -07:00
Matthieu Riegler
6a6cb01bb3 docs: update NG_VALIDATORS examples to use forwardRef (#63247)
PR Close #63247
2025-08-20 09:27:20 +00:00
Bjorn 'Bjeaurn
c353497a01 feat(forms): add support for pushing an array of controls to formarray (#57102)
Enables users to add an array of FormControls to a FormArray using its existing .push() method,
instead of pushing each new FormControl one by one triggering events along the way.

PR Close #57102
2025-08-06 11:20:18 +02:00
Joey Perrott
fa8d8b8396 build: migrate all npm packages to use new rules_js based npm_package rule (#62954)
Use a common rule for all npm_packages

PR Close #62954
2025-08-05 19:08:45 +00:00
Joey Perrott
cbc258eec8 build: remove ts_project_interop infrastructure (#62908)
Remove the interop macros and final usages

PR Close #62908
2025-07-31 09:12:58 +00:00
Joey Perrott
793ff35602 build: move http_server and generate_api_docs into defaults2.bzl (#62878)
Move http_server and generate_api_docs into defaults2.bzl as they are rules_js compliant

PR Close #62878
2025-07-29 16:53:54 +00:00
SkyZeroZx
8ebc1e7d8c refactor(forms): Removes redundant destroy ref usage in value accessor in select control (#62738)
Simplifies destruction logic by relying directly on the injector's destroyed state.
Eliminates unnecessary retrieval of a separate destroy reference

PR Close #62738
2025-07-24 13:25:30 +00:00
Joey Perrott
8bf97d1370 build: remove all usages of the interop_deps attr for ts_project and ng_project (#62732)
Remove all of the usages of interop_deps as attributes in the repo

PR Close #62732
2025-07-21 13:03:09 -04:00
Joey Perrott
23d58777b4 build: migrate to new toolchain usage for api goldens (#62688)
Migrate api golden usage to be based on rules_js toolchain implementation

PR Close #62688
2025-07-17 18:13:42 -04:00
Joey Perrott
b84859073b build: migrate to use web test runner rules (#62292)
Migrate karma tests throughout the repo to use the new web test runner based rule instead

PR Close #62292
2025-06-26 17:19:10 +00:00
Joey Perrott
36d5048429 build: migrate final non-zone.js jasmine tests (#62169)
Migrate the final remaining non-zone.js package jasmine tests to the new toolchain

PR Close #62169
2025-06-24 08:46:39 +00:00
Theodore Brown
4f0221e193 fix(forms): improve select performance (#61949)
We defer the update until after rendering
is complete for two reasons: first, to avoid repeatedly calling
`writeValue` on every option element until we find the selected one
(could be the very last element). Second, to ensure that we perform the
write after the DOM elements have been created (this doesn't happen
until the end of change detection when animations are enabled).

This is needed to efficiently set the select value when adding/removing options. The
previous approach resulted in exponentially more `_compareValue` calls than the number
of option elements (issue angular#41330).

Finally, this PR fixes an issue with delayed element removal when using the animations
module (in all browsers). Previously when a selected option was removed (so no option
matched the ngModel anymore), Angular changed the select element value before actually
removing the option from the DOM. Then when the option was finally removed from the DOM,
the browser would change the select value to that of the first option, even though it
didn't match the ngModel (issue angular#18430). Note that this is still
somewhat of an application problem when using `ngModel`. The model value
still needs to be updated to a valid value when the selected value is
deleted or it will be out of sync with the DOM.

Fixes #41330, fixes #18430.

PR Close #61949
2025-06-10 13:13:13 -07:00
Paul Gschwendtner
d081ef9b06 build: replace all ng_package with new rule from rules_angular (#61843)
Replaces all `ng_package` rule with the new rule from `rules_angular`.

PR Close #61843
2025-06-04 09:13:41 +00:00
Matthieu Riegler
e7608e503f docs: update API examples to modern angular (#61688)
PR Close #61688
2025-05-29 17:53:28 -04:00
Paul Gschwendtner
b80957d1c5 build: adjust bundling tests to use Angular CLI (#61566)
Instead of dev-infra maintaining a custom ESBuild + Terser pipeline that
tries to emulate the Angular CLI, we are switching the bundling core
tests to a new rule that really leverages the Angular CLI.

This involves some file renames and small adjustments. In addition, we
leverage the updated symbol tracking rule to output new goldens that can
work with multiple bundle files (as generated by the Angular CLI;
especially with defer and its "lazy" chunks).

PR Close #61566
2025-05-29 14:39:11 -04:00
Bouguima, Walid
610bebfce9 fix(forms): Allow ControlState as reset arguments for FormGroup/FormRecord (#55860)
This change also decorelate the `reset` type argument from `TValue` by adding a 3rd generic parameter to `AbstractControl`.
This improves the typings overall.

PR Close #55860
2025-05-21 17:26:23 +00:00
Joey Perrott
e11f48f65e build: migrate forms to rules_js (#61535)
Migrate forms to use ng_project and ts_project

PR Close #61535
2025-05-21 09:16:05 +00:00
Alan Agius
8f65223bd8 fix(core): update min Node.js support to 20.19, 22.12, and 24.0 (#61499)
This is to match the versions of the Angular CLI.

See: https://github.com/angular/angular-cli/pull/30349

PR Close #61499
2025-05-20 14:15:13 +00:00
Paul Gschwendtner
3a106a35bc build: move private testing helpers outside platform-browser/testing (#61472)
These helpers are often imported by various tests throughout the
repository, but the helpers aren't exported/exposed from the public
entry-point; even though they confusingly reside in there.

This commit fixes this, and moves the helpers into
`packages/private/testing`. This is a preparation for the `ts_project`
migration where we don't want to leverage deep imports between packages.

PR Close #61472
2025-05-20 10:00:43 +00:00
Miles Malerba
c0e9fc103f docs: rename @nodoc to @docs-private (#61194)
This aligns with how angular/components marks their hidden APIs.
`@nodoc` has been broken since the switch to adev, this change should
properly hide the APIs again.

PR Close #61194
2025-05-09 10:23:00 -07:00
Paul Gschwendtner
032b802f54 build: remove irrelevant madge circular deps tests (#61156)
We don't need this tooling anymore because we are already validating
that there are no circular dependencies via the `ng-dev` tooling that
checks `.ts` files directly.

Also these tests never actually failed to my knowledge.

PR Close #61156
2025-05-07 11:28:59 -07:00
Alan Agius
d5c6f2c4de refactor: add Node.js 24 as supported version (#61142)
Node.js 24 has been released https://nodejs.org/en/about/previous-releases

Closes: #61140

PR Close #61142
2025-05-06 13:38:25 -07:00
Andrew Scott
953c4b2580 feat(core): Move zoneless change detection to dev preview (#60748)
This commit moves zoneless from experimental to developer preview.

* Update tag on provider API
* Remove "experimental" from provider name
* Move documentation from "experimental features" to "Best practives ->
  Performance" (at least temporarily until there is a better place)

BREAKING CHANGE: `provideExperimentalZonelessChangeDetection` is
renamed to `provideZonelessChangeDetection` as it is now "Developer
Preview" rather than "Experimental".

PR Close #60748
2025-04-23 11:47:56 +02:00
Gabriel Bergoc
be995623cd fix(forms): make NgForm emit FormSubmittedEvent and FormResetEvent (#60887)
Currently, only forms created with `FormGroupDirective` emit events on
form submission and resetting. This commit extends this behavior to
Template-driven forms also.

Related to #58894

PR Close #60887
2025-04-22 13:04:40 +02:00
Domenico Gemoli
a07ee60989 feat(forms): add markAllAsDirty to AbstractControl (#58663)
Adds the `markAllAsDirty` method to the `AbstractControl` class. This method will mark the control and all its
descendants as dirty.

I pretty much just duplicated the behaviour and tests of `markAllAsTouched`.

Fixes #55990

PR Close #58663
2025-04-02 18:25:32 +00:00
Matthieu Riegler
bdfbd54932 feat(forms): Allow to reset a form without emitting events (#60354)
This change  add an option paramter to `resetForm` that is passed to the FormGroup.

fixes #60274

PR Close #60354
2025-04-02 11:36:24 +00:00
Matthieu Riegler
51c303a45c refactor(core): remove TODOs referencing #24571 (#60648)
Fixing those todos are now mostly breaking changes.
The situation is "good" as is.

PR Close #60648
2025-03-31 20:24:29 +00:00