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
@@ -109,8 +110,8 @@ The template is wrapped in a `<form>` tag with an `(ngSubmit)` event and a submi
109
110
110
111
- The `[control]` directive automatically handles the two-way data binding between the input element and the corresponding `Field` in the `profileForm`.
111
112
- The `profileForm()` signal gives you access to the `FieldState`, which includes the form's `value` as a signal.
112
-
- The `(ngSubmit)` event on the `<form>` element is bound to the `handleSubmit` method in the component.
113
-
-When`handleSubmit`is called, it emits the current form value through the `submitted` output property.
113
+
- The native `(submit)` event on the `<form>` element is bound to the `handleSubmit` method. It's important to call `$event.preventDefault()` to prevent a full page reload.
114
+
-The`handleSubmit`method uses the `submit()` helper to manage the submission process.
@if (error.pattern) { <p>Please enter a valid URL.</p> }
159
+
@switch (error.kind) {
160
+
@case ('pattern') { <p>Please enter a valid URL.</p> }
161
+
}
157
162
}
158
163
</div>
159
164
}
@@ -166,7 +171,8 @@ This file provides the template for the form, displaying specific error messages
166
171
## Usage Notes
167
172
168
173
- All built-in validators are imported directly from `@angular/forms`.
169
-
- Each validator is a function that takes the `FieldPath` as its first argument, and optional configuration (like the minimum length) as the second.
174
+
- The native `(submit)` event on the `<form>` element is bound to the `handleSubmit` method. It's important to call `$event.preventDefault()` to prevent a full page reload.
175
+
- The `handleSubmit` method uses the `submit()` helper to manage the submission process.
Copy file name to clipboardExpand all lines: packages/forms/signals/examples/03-cross-field-validation.md
+20-16Lines changed: 20 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
2
title: Signal Form with Cross-Field Validation
3
-
summary: Implements a cross-field validator by applying a validator to one field that reactively depends on the value of another field.
3
+
summary: Implements a cross-field validator by applying a validator to one field that reactively depends on the value of another field using `valueOf`.
4
4
keywords:
5
5
- signal forms
6
6
- form
@@ -29,7 +29,7 @@ Use this pattern when the validity of one form field depends on the value of ano
29
29
30
30
-**`validate()`:** A function used within a schema to add a validator to a specific field.
31
31
-**`valueOf()`:** A function available in the validation context that allows you to reactively access the value of any other field in the form.
32
-
-**`valid` signal:**A signal on the `FieldState`that is `true` only when the field and all its descendants are valid.
32
+
-**`submit()`:**An async helper function that manages the form's submission state and should be called from the submit event handler.
33
33
34
34
## Example Files
35
35
@@ -41,7 +41,7 @@ This file defines the component's logic. The schema applies a validator to `conf
@for (error of passwordForm.confirmPassword().errors()) {
120
-
@if (error.mismatch) { <p>Passwords do not match.</p> }
122
+
@switch (error.kind) {
123
+
@case ('mismatch') { <p>Passwords do not match.</p> }
124
+
}
121
125
}
122
126
</div>
123
127
}
@@ -129,8 +133,8 @@ This file provides the template for the form, showing how to display errors for
129
133
130
134
## Usage Notes
131
135
132
-
- The submit button is disabled based on the form's `valid` signal (`[disabled]="!passwordForm().valid()"`).
133
-
- The `handleSubmit` method checks `this.passwordForm().valid()` as a safeguard before emitting the data.
136
+
- The native `(submit)` event on the `<form>` element is bound to the `handleSubmit` method. It's important to call `$event.preventDefault()` to prevent a full page reload.
137
+
- The `handleSubmit` method uses the `submit()` helper to manage the submission process.
0 commit comments