You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/forms/signals/examples/03-cross-field-validation.md
+10-10Lines changed: 10 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,13 @@
1
1
---
2
2
title: Signal Form with Cross-Field Validation
3
-
summary: Implements a cross-field validator using `validateTree` to ensure two fields in a signal form are consistent with each other.
3
+
summary: Implements a cross-field validator by applying a validator to one field that reactively depends on the value of another field.
4
4
keywords:
5
5
- signal forms
6
6
- form
7
7
- control
8
8
- validation
9
9
- cross-field validation
10
-
- validateTree
10
+
- valueOf
11
11
- schema
12
12
- minLength
13
13
- submit
@@ -23,25 +23,25 @@ The purpose of this pattern is to implement validation logic that depends on the
23
23
24
24
## When to Use
25
25
26
-
Use this pattern when the validity of one form field depends on the value of another. This is common in registration forms, password change forms, and any form where two fields must be consistent with each other. `validateTree` is the signal-based equivalent of a cross-field validator on a `FormGroup`in `ReactiveFormsModule`.
26
+
Use this pattern when the validity of one form field depends on the value of another. This is common in registration forms, password change forms, and any form where two fields must be consistent with each other. The recommended approach is to apply a validator to the field where the error should be reported (e.g., `confirmPassword`) and use the `valueOf` function in the validation context to reactively get the value of the other field it depends on (e.g., `password`).
27
27
28
28
## Key Concepts
29
29
30
-
-**`validateTree()`:** A function used within a schema to add a validator to a form group or the entire form.
30
+
-**`validate()`:** A function used within a schema to add a validator to a specific field.
31
+
-**`valueOf()`:** A function available in the validation context that allows you to reactively access the value of any other field in the form.
31
32
-**`valid` signal:** A signal on the `FieldState` that is `true` only when the field and all its descendants are valid.
32
-
-**`(ngSubmit)`:** An event binding on a `<form>` element that triggers a method when the form is submitted.
33
33
34
34
## Example Files
35
35
36
36
This example consists of a standalone component that defines and manages a password change form.
37
37
38
38
### password-form.component.ts
39
39
40
-
This file defines the component's logic, including a schema with a `validateTree` function for cross-field validation.
40
+
This file defines the component's logic. The schema applies a validator to `confirmPassword` that compares its value to the value of the `password` field.
Copy file name to clipboardExpand all lines: packages/forms/signals/examples/09-async-validation.md
+51-51Lines changed: 51 additions & 51 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,17 +1,18 @@
1
1
---
2
2
title: Signal Form with Asynchronous Validation
3
-
summary: Implements an asynchronous validator on a signal form field using `validateAsync` to check for a unique username against a mock backend service.
3
+
summary: Implements an asynchronous validator on a signal form field using `validateHttp` to check for a unique username against a mock backend endpoint.
4
4
keywords:
5
5
- signal forms
6
6
- form
7
7
- control
8
8
- validation
9
9
- asynchronous validation
10
10
- async
11
-
- validateAsync
11
+
- validateHttp
12
12
- schema
13
13
required_packages:
14
14
- '@angular/forms'
15
+
- '@angular/common'
15
16
related_concepts:
16
17
- 'signals'
17
18
---
@@ -22,68 +23,37 @@ The purpose of this pattern is to perform validation that requires an asynchrono
22
23
23
24
## When to Use
24
25
25
-
Use this pattern for validation that requires a network request, a debounce, or any other asynchronous operation. It allows the UI to remain responsive while the validation is in progress and provides feedback to the user once the validation is complete. This is the modern, signal-based equivalent of `AsyncValidator` in `ReactiveFormsModule`.
26
+
Use this pattern for validation that requires a network request. The `validateHttp` function provides a convenient, built-in way to integrate backend validation. It allows the UI to remain responsive while the validation is in progress and provides feedback to the user once the validation is complete. This is the modern, signal-based equivalent of `AsyncValidator` in `ReactiveFormsModule`.
26
27
27
28
## Key Concepts
28
29
29
-
-**`validateAsync()`:** A function used within a schema to add an asynchronous validator to a field.
30
-
-**Asynchronous Validator Function:** A function that returns a `Promise` which resolves to an error object or `null`.
30
+
-**`validateHttp()`:** A function used within a schema to add an asynchronous validator to a field based on an HTTP request.
31
31
-**`pending` signal:** A signal on the `FieldState` that is `true` while an asynchronous validator is running.
32
32
33
33
## Example Files
34
34
35
-
This example consists of a standalone component and a service that work together to perform asynchronous validation.
36
-
37
-
### username.service.ts
38
-
39
-
This file defines a mock service that simulates an asynchronous check for username uniqueness.
0 commit comments