mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
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:
committed by
Leon Senft
parent
dd208ca259
commit
95ecce8334
@@ -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);
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user