Skip to content

Commit b32b010

Browse files
feat(core): form reset field utility function (#1223)
Co-authored-by: Harry Whorlow <whorlowharry@gmail.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 281075c commit b32b010

34 files changed

+226
-160
lines changed

docs/reference/classes/fieldapi.md

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ title: FieldApi
77

88
# Class: FieldApi\<TParentData, TName, TData, TOnMount, TOnChange, TOnChangeAsync, TOnBlur, TOnBlurAsync, TOnSubmit, TOnSubmitAsync, TFormOnMount, TFormOnChange, TFormOnChangeAsync, TFormOnBlur, TFormOnBlurAsync, TFormOnSubmit, TFormOnSubmitAsync, TFormOnServer, TParentSubmitMeta\>
99

10-
Defined in: [packages/form-core/src/FieldApi.ts:859](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L859)
10+
Defined in: [packages/form-core/src/FieldApi.ts:860](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L860)
1111

1212
A class representing the API for managing a form field.
1313

@@ -65,7 +65,7 @@ the `new FieldApi` constructor.
6565
new FieldApi<TParentData, TName, TData, TOnMount, TOnChange, TOnChangeAsync, TOnBlur, TOnBlurAsync, TOnSubmit, TOnSubmitAsync, TFormOnMount, TFormOnChange, TFormOnChangeAsync, TFormOnBlur, TFormOnBlurAsync, TFormOnSubmit, TFormOnSubmitAsync, TFormOnServer, TParentSubmitMeta>(opts): FieldApi<TParentData, TName, TData, TOnMount, TOnChange, TOnChangeAsync, TOnBlur, TOnBlurAsync, TOnSubmit, TOnSubmitAsync, TFormOnMount, TFormOnChange, TFormOnChangeAsync, TFormOnBlur, TFormOnBlurAsync, TFormOnSubmit, TFormOnSubmitAsync, TFormOnServer, TParentSubmitMeta>
6666
```
6767

68-
Defined in: [packages/form-core/src/FieldApi.ts:973](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L973)
68+
Defined in: [packages/form-core/src/FieldApi.ts:974](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L974)
6969

7070
Initializes a new `FieldApi` instance.
7171

@@ -87,7 +87,7 @@ Initializes a new `FieldApi` instance.
8787
form: FormApi<TParentData, TFormOnMount, TFormOnChange, TFormOnChangeAsync, TFormOnBlur, TFormOnBlurAsync, TFormOnSubmit, TFormOnSubmitAsync, TFormOnServer, TParentSubmitMeta>;
8888
```
8989

90-
Defined in: [packages/form-core/src/FieldApi.ts:889](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L889)
90+
Defined in: [packages/form-core/src/FieldApi.ts:890](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L890)
9191

9292
A reference to the form API instance.
9393

@@ -99,7 +99,7 @@ A reference to the form API instance.
9999
name: unknown extends TParentData ? string : TParentData extends readonly any[] & IsTuple<TParentData> ? PrefixTupleAccessor<TParentData<TParentData>, AllowedIndexes<TParentData<TParentData>, never>, []> : TParentData extends any[] ? PrefixArrayAccessor<TParentData<TParentData>, [any]> : TParentData extends Date ? never : TParentData extends object ? PrefixObjectAccessor<TParentData<TParentData>, []> : TParentData extends string | number | bigint | boolean ? "" : never;
100100
```
101101

102-
Defined in: [packages/form-core/src/FieldApi.ts:913](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L913)
102+
Defined in: [packages/form-core/src/FieldApi.ts:914](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L914)
103103

104104
The field name.
105105

@@ -111,7 +111,7 @@ The field name.
111111
options: FieldApiOptions<TParentData, TName, TData, TOnMount, TOnChange, TOnChangeAsync, TOnBlur, TOnBlurAsync, TOnSubmit, TOnSubmitAsync, TFormOnMount, TFormOnChange, TFormOnChangeAsync, TFormOnBlur, TFormOnBlurAsync, TFormOnSubmit, TFormOnSubmitAsync, TFormOnServer, TParentSubmitMeta>;
112112
```
113113

114-
Defined in: [packages/form-core/src/FieldApi.ts:917](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L917)
114+
Defined in: [packages/form-core/src/FieldApi.ts:918](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L918)
115115

116116
The field options.
117117

@@ -123,7 +123,7 @@ The field options.
123123
store: Derived<FieldState<TParentData, TName, TData, TOnMount, TOnChange, TOnChangeAsync, TOnBlur, TOnBlurAsync, TOnSubmit, TOnSubmitAsync, TFormOnMount, TFormOnChange, TFormOnChangeAsync, TFormOnBlur, TFormOnBlurAsync, TFormOnSubmit, TFormOnSubmitAsync>>;
124124
```
125125

126-
Defined in: [packages/form-core/src/FieldApi.ts:941](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L941)
126+
Defined in: [packages/form-core/src/FieldApi.ts:942](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L942)
127127

128128
The field state store.
129129

@@ -135,7 +135,7 @@ The field state store.
135135
timeoutIds: Record<ValidationCause, null | Timeout>;
136136
```
137137

138-
Defined in: [packages/form-core/src/FieldApi.ts:968](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L968)
138+
Defined in: [packages/form-core/src/FieldApi.ts:969](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L969)
139139

140140
## Accessors
141141

@@ -147,7 +147,7 @@ Defined in: [packages/form-core/src/FieldApi.ts:968](https://github.com/TanStack
147147
get state(): FieldState<TParentData, TName, TData, TOnMount, TOnChange, TOnChangeAsync, TOnBlur, TOnBlurAsync, TOnSubmit, TOnSubmitAsync, TFormOnMount, TFormOnChange, TFormOnChangeAsync, TFormOnBlur, TFormOnBlurAsync, TFormOnSubmit, TFormOnSubmitAsync>
148148
```
149149

150-
Defined in: [packages/form-core/src/FieldApi.ts:965](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L965)
150+
Defined in: [packages/form-core/src/FieldApi.ts:966](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L966)
151151

152152
The current field state.
153153

@@ -163,7 +163,7 @@ The current field state.
163163
getInfo(): FieldInfo<TParentData>
164164
```
165165

166-
Defined in: [packages/form-core/src/FieldApi.ts:1221](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1221)
166+
Defined in: [packages/form-core/src/FieldApi.ts:1216](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1216)
167167

168168
Gets the field information object.
169169

@@ -179,7 +179,7 @@ Gets the field information object.
179179
getMeta(): FieldMeta<TParentData, TName, TData, TOnMount, TOnChange, TOnChangeAsync, TOnBlur, TOnBlurAsync, TOnSubmit, TOnSubmitAsync, TFormOnMount, TFormOnChange, TFormOnChangeAsync, TFormOnBlur, TFormOnBlurAsync, TFormOnSubmit, TFormOnSubmitAsync>
180180
```
181181

182-
Defined in: [packages/form-core/src/FieldApi.ts:1189](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1189)
182+
Defined in: [packages/form-core/src/FieldApi.ts:1184](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1184)
183183

184184
#### Returns
185185

@@ -193,7 +193,7 @@ Defined in: [packages/form-core/src/FieldApi.ts:1189](https://github.com/TanStac
193193
getValue(): TData
194194
```
195195

196-
Defined in: [packages/form-core/src/FieldApi.ts:1171](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1171)
196+
Defined in: [packages/form-core/src/FieldApi.ts:1166](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1166)
197197

198198
Gets the current field value.
199199

@@ -213,7 +213,7 @@ Use `field.state.value` instead.
213213
handleBlur(): void
214214
```
215215

216-
Defined in: [packages/form-core/src/FieldApi.ts:1632](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1632)
216+
Defined in: [packages/form-core/src/FieldApi.ts:1627](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1627)
217217

218218
Handles the blur event.
219219

@@ -229,7 +229,7 @@ Handles the blur event.
229229
handleChange(updater): void
230230
```
231231

232-
Defined in: [packages/form-core/src/FieldApi.ts:1625](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1625)
232+
Defined in: [packages/form-core/src/FieldApi.ts:1620](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1620)
233233

234234
Handles the change event.
235235

@@ -254,7 +254,7 @@ insertValue(
254254
opts?): void
255255
```
256256
257-
Defined in: [packages/form-core/src/FieldApi.ts:1241](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1241)
257+
Defined in: [packages/form-core/src/FieldApi.ts:1236](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1236)
258258
259259
Inserts a value at the specified index, shifting the subsequent values to the right.
260260
@@ -284,7 +284,7 @@ Inserts a value at the specified index, shifting the subsequent values to the ri
284284
mount(): () => void
285285
```
286286
287-
Defined in: [packages/form-core/src/FieldApi.ts:1077](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1077)
287+
Defined in: [packages/form-core/src/FieldApi.ts:1072](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1072)
288288
289289
Mounts the field instance to the form.
290290
@@ -307,7 +307,7 @@ moveValue(
307307
opts?): void
308308
```
309309
310-
Defined in: [packages/form-core/src/FieldApi.ts:1297](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1297)
310+
Defined in: [packages/form-core/src/FieldApi.ts:1292](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1292)
311311
312312
Moves the value at the first specified index to the second specified index.
313313
@@ -337,7 +337,7 @@ Moves the value at the first specified index to the second specified index.
337337
pushValue(value, opts?): void
338338
```
339339
340-
Defined in: [packages/form-core/src/FieldApi.ts:1226](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1226)
340+
Defined in: [packages/form-core/src/FieldApi.ts:1221](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1221)
341341
342342
Pushes a new value to the field.
343343
@@ -363,7 +363,7 @@ Pushes a new value to the field.
363363
removeValue(index, opts?): void
364364
```
365365
366-
Defined in: [packages/form-core/src/FieldApi.ts:1273](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1273)
366+
Defined in: [packages/form-core/src/FieldApi.ts:1268](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1268)
367367
368368
Removes a value at the specified index.
369369
@@ -392,7 +392,7 @@ replaceValue(
392392
opts?): void
393393
```
394394
395-
Defined in: [packages/form-core/src/FieldApi.ts:1257](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1257)
395+
Defined in: [packages/form-core/src/FieldApi.ts:1252](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1252)
396396
397397
Replaces a value at the specified index.
398398
@@ -422,7 +422,7 @@ Replaces a value at the specified index.
422422
setErrorMap(errorMap): void
423423
```
424424
425-
Defined in: [packages/form-core/src/FieldApi.ts:1652](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1652)
425+
Defined in: [packages/form-core/src/FieldApi.ts:1647](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1647)
426426
427427
Updates the field's errorMap
428428
@@ -444,7 +444,7 @@ Updates the field's errorMap
444444
setMeta(updater): void
445445
```
446446
447-
Defined in: [packages/form-core/src/FieldApi.ts:1194](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1194)
447+
Defined in: [packages/form-core/src/FieldApi.ts:1189](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1189)
448448
449449
Sets the field metadata.
450450
@@ -466,7 +466,7 @@ Sets the field metadata.
466466
setValue(updater, options?): void
467467
```
468468
469-
Defined in: [packages/form-core/src/FieldApi.ts:1178](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1178)
469+
Defined in: [packages/form-core/src/FieldApi.ts:1173](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1173)
470470
471471
Sets the field value and run the `change` validator.
472472
@@ -495,7 +495,7 @@ swapValues(
495495
opts?): void
496496
```
497497
498-
Defined in: [packages/form-core/src/FieldApi.ts:1285](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1285)
498+
Defined in: [packages/form-core/src/FieldApi.ts:1280](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1280)
499499
500500
Swaps the values at the specified indices.
501501
@@ -525,7 +525,7 @@ Swaps the values at the specified indices.
525525
update(opts): void
526526
```
527527
528-
Defined in: [packages/form-core/src/FieldApi.ts:1119](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1119)
528+
Defined in: [packages/form-core/src/FieldApi.ts:1114](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1114)
529529
530530
Updates the field instance with new options.
531531
@@ -547,7 +547,7 @@ Updates the field instance with new options.
547547
validate(cause, opts?): unknown[] | Promise<unknown[]>
548548
```
549549
550-
Defined in: [packages/form-core/src/FieldApi.ts:1592](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1592)
550+
Defined in: [packages/form-core/src/FieldApi.ts:1587](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldApi.ts#L1587)
551551
552552
Validates the field value.
553553

0 commit comments

Comments
 (0)