feat(forms): allow setting submit options at form-level

Updates FormOptions to accept a submission configuration object.
This allows defining default submit options (action, validation behavior, etc.)
when creating the form, which can be overridden when calling submit().
This commit is contained in:
Miles Malerba
2026-01-20 10:03:36 -08:00
committed by Leon Senft
parent dd208ca259
commit 95ecce8334
10 changed files with 154 additions and 58 deletions
@@ -1,3 +1,11 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {ChangeDetectionStrategy, Component, signal} from '@angular/core';
import {email, form, FormField, required, submit} from '@angular/forms/signals';
@@ -28,11 +36,13 @@ export class App {
onSubmit(event: Event) {
event.preventDefault();
submit(this.loginForm, async () => {
const credentials = this.loginModel();
// In a real app, this would be async:
// await this.authService.login(credentials);
console.log('Logging in with:', credentials);
submit(this.loginForm, {
action: async () => {
const credentials = this.loginModel();
// In a real app, this would be async:
// await this.authService.login(credentials);
console.log('Logging in with:', credentials);
},
});
}
}