Open History to see the last commit
1---
2id: quick-start
3title: Quick Start
4---
5β
6The bare minimum to get started with TanStack Form is to create a `TanstackFormController` as seen below with the `Employee` interface for our test form:
7β
8```ts
9interface Employee {
10 firstName: string
11 lastName: string
12 employed: boolean
13 jobTitle: string
14}
15β
16#form = new TanStackFormController()<Employee>(this, {
17 defaultValues: {
18 firstName: '',
19 lastName: '',
20 employed: false,
21 jobTitle: '',
22 },
23})
24```
25β
26In this example `this` references the instance of your `LitElement` in which you want to use TanStack Form.
27β
28To wire a form element in your template up with TanStack Form, use the `field` method of `TanstackFormController`.
29β
30The first parameter of `field` is `FieldOptions` and the second is callback to render your element.
31β
32```ts
33field(FieldOptions, callback)
34```
35β
36Our completed test form should look something like below. The form collects first name from a user input field:
37β
38```ts
39export class TestForm extends LitElement {
40 #form = new TanStackFormController<Employee>(this, {
41 defaultValues: {
42 firstName: '',
43 lastName: '',
44 employed: false,
45 jobTitle: '',
46 },
47 })
48 render() {
49 return html` <p>Please enter your first name</p>
50 ${this.#form.field(
51 {
52 name: `firstName`,
53 validators: {
54 onChange: ({ value }) =>
55 value.length < 3 ? 'Not long enough' : undefined,
56 },
57 },
58 (field: FieldApi<Employee, 'firstName'>) => {
59 return html` <div>
60 <label class="first-name-label">First Name</label>
61 <input
62 id="firstName"
63 type="text"
64 placeholder="First Name"
65 @blur="${() => field.handleBlur()}"
66 .value="${field.getValue()}"
67 @input="${(event: InputEvent) => {
68 if (event.currentTarget) {
69 const newValue = (event.currentTarget as HTMLInputElement)
70 .value
71 field.handleChange(newValue)
72 }
73 }}"
74 />
75 </div>`
76 },
77 )}`
78 }
79}
80```
81β
82Be aware that you need
83to handle updating the element and form yourself as seen in the example above.