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

FormApiFieldMethods.md

94 lines2.2 KB

1---
2id: FormApiFieldMethods
3title: FormApiFieldMethods
4---
5​
6Defined in: [FormApi/FormApiFieldMethods.types.public.ts:85](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi/FormApiFieldMethods.types.public.ts#L85)
7​
8Type-safe methods for reading, updating, and resetting individual field
9values.
10​
11## Extended by
12​
13- [`FormApi`](FormApi.md)
14​
15## Type Parameters
16​
17### TFormData
18​
19`TFormData`
20​
21Library-managed. Do not specify explicitly.
22​
23## Properties
24​
25### getFieldValue
26​
27```ts
28getFieldValue: GetFieldValueFn<TFormData>;
29```
30​
31Defined in: [FormApi/FormApiFieldMethods.types.public.ts:114](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi/FormApiFieldMethods.types.public.ts#L114)
32​
33Reads the current value at a field path.
34​
35This is a read-only operation and does not create a `FieldApi` for the path.
36​
37#### Example
38​
39```ts
40const name = formApi.getFieldValue('profile.name')
41```
42​
43#### Returns
44​
45The current value at the path, or `undefined` when the path cannot
46be resolved at runtime.
47​
48***
49​
50### resetField
51​
52```ts
53resetField: ResetFieldFn<TFormData>;
54```
55​
56Defined in: [FormApi/FormApiFieldMethods.types.public.ts:131](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi/FormApiFieldMethods.types.public.ts#L131)
57​
58Restores a field path from `defaultValues` and resets state for its field
59subtree.
60​
61Existing `FieldApi` instances at or below the path remain mounted.
62Form-wide dirty history remains unchanged; use `formApi.reset()` to clear
63it.
64​
65#### Example
66​
67```ts
68formApi.setFieldValue('profile.name', 'Grace')
69formApi.resetField('profile.name')
70// `profile.name` is restored from `defaultValues`.
71```
72​
73***
74​
75### setFieldValue
76​
77```ts
78setFieldValue: SetFieldValueFn<TFormData>;
79```
80​
81Defined in: [FormApi/FormApiFieldMethods.types.public.ts:99](https://github.com/TanStack/form/blob/main/packages/form-core/src/FormApi/FormApiFieldMethods.types.public.ts#L99)
82​
83Updates the current value at a field path.
84​
85The next value may be supplied directly or calculated from the current
86value. By default, the update marks the field as touched and dirty,
87notifies change listeners, and runs change validation.
88​
89#### Example
90​
91```ts
92formApi.setFieldValue('profile.name', 'Ada')
93formApi.setFieldValue('visitCount', (count) => count + 1)
94```