Open History to see the last commit
1import { ChangeDetectionStrategy, Component, input } from '@angular/core'
2import {
3 TanStackAppField,
4 TanStackField,
5 TanStackFormGroup,
6} from '@tanstack/angular-form'
7import { step2Schema, stepValidator } from './shared-form'
8import { TextFieldComponent } from './text-field.component'
9import type { AngularFormType } from '@tanstack/angular-form'
10import type { wizardFormOptions } from './shared-form'
11β
12@Component({
13 selector: 'app-step-two',
14 standalone: true,
15 changeDetection: ChangeDetectionStrategy.OnPush,
16 imports: [
17 TanStackAppField,
18 TanStackField,
19 TanStackFormGroup,
20 TextFieldComponent,
21 ],
22 template: `
23 <ng-container
24 [tanstackFormGroup]="form()"
25 name="step2"
26 [validators]="validators"
27 [onSubmit]="onSubmit"
28 #group="formGroup"
29 >
30 <form (submit)="submit($event, group.api)">
31 <h2>Step 2</h2>
32 <app-text-field
33 label="Step 2 Name"
34 tanstack-app-field
35 [tanstackField]="group.api"
36 name="name"
37 />
38 <div class="actions">
39 <button type="button" (click)="back()()">Back</button>
40 <button type="submit" [disabled]="group.api.state.isSubmitting">
41 Submit
42 </button>
43 </div>
44 </form>
45 </ng-container>
46 `,
47})
48export class StepTwoComponent {
49 form = input.required<AngularFormType<typeof wizardFormOptions>>()
50 back = input.required<() => void>()
51 validators = [stepValidator(step2Schema)]
52 onSubmit = () => {
53 void this.form().handleSubmit()
54 }
55β
56 submit(event: SubmitEvent, group: { handleSubmit: () => unknown }) {
57 event.preventDefault()
58 event.stopPropagation()
59 group.handleSubmit()
60 }
61}