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