Skip to content
Source
Sign inSign up
TanStack/form
Open History to see the last commit

quick-start.md

59 lines1.5 KB

1---
2id: quick-start
3title: Quick Start
4---
5​
6The bare minimum to get started with TanStack Form is to create a form and add a field. Keep in mind that this example does not include any validation or error handling... yet.
7​
8```angular-ts
9import { Component } from '@angular/core'
10import { bootstrapApplication } from '@angular/platform-browser'
11import { TanStackField, injectForm } from '@tanstack/angular-form'
12​
13@Component({
14 selector: 'app-root',
15 standalone: true,
16 imports: [TanStackField],
17 template: `
18 <form (submit)="handleSubmit($event)">
19 <div>
20 <ng-container
21 [tanstackField]="form"
22 name="fullName"
23 #fullName="field"
24 >
25 <label [for]="fullName.api.name">First Name:</label>
26 <input
27 [name]="fullName.api.name"
28 [value]="fullName.api.state.value"
29 (blur)="fullName.api.handleBlur()"
30 (input)="fullName.api.handleChange($any($event).target.value)"
31 />
32 </ng-container>
33 </div>
34 <button type="submit">Submit</button>
35 </form>
36 `,
37})
38export class AppComponent {
39 form = injectForm({
40 defaultValues: {
41 fullName: '',
42 },
43 onSubmit({ value }) {
44 // Do something with form data
45 console.log(value)
46 },
47 })
48​
49 handleSubmit(event: SubmitEvent) {
50 event.preventDefault()
51 event.stopPropagation()
52 this.form.handleSubmit()
53 }
55​
56bootstrapApplication(AppComponent).catch((err) => console.error(err))
57```
58​
59From here, you'll be ready to explore all of the other features of TanStack Form!