Skip to content

Commit 54f2094

Browse files
author
Harry Whorlow
committed
chore: pr comment
1 parent e2294eb commit 54f2094

File tree

3 files changed

+21
-27
lines changed

3 files changed

+21
-27
lines changed

packages/form-core/src/FieldApi.ts

+7-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ import {
33
isStandardSchemaValidator,
44
standardSchemaValidators,
55
} from './standardSchemaValidator'
6-
import { getAsyncValidatorArray, getBy, getSyncValidatorArray } from './utils'
6+
import {
7+
defaultFieldMeta,
8+
getAsyncValidatorArray,
9+
getBy,
10+
getSyncValidatorArray,
11+
} from './utils'
712
import type { DeepKeys, DeepValue, UnwrapOneLevelOfArray } from './util-types'
813
import type {
914
StandardSchemaV1,
@@ -1007,13 +1012,7 @@ export class FieldApi<
10071012
fn: () => {
10081013
const value = this.form.getFieldValue(this.name)
10091014
const meta = this.form.getFieldMeta(this.name) ?? {
1010-
isValidating: false,
1011-
isTouched: false,
1012-
isBlurred: false,
1013-
isDirty: false,
1014-
isPristine: true,
1015-
errors: [],
1016-
errorMap: {},
1015+
defaultFieldMeta,
10171016
...opts.defaultMeta,
10181017
}
10191018

packages/form-core/src/FormApi.ts

+3-18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Derived, Store, batch } from '@tanstack/store'
22
import {
3+
defaultFieldMeta,
34
deleteBy,
45
functionalUpdate,
56
getAsyncValidatorArray,
@@ -1724,15 +1725,7 @@ export class FormApi<
17241725
return Object.keys(fieldMeta).reduce(
17251726
(acc: Record<TField, AnyFieldMeta>, key) => {
17261727
const fieldKey = key as TField
1727-
acc[fieldKey] = {
1728-
isValidating: false,
1729-
isTouched: false,
1730-
isBlurred: false,
1731-
isDirty: false,
1732-
isPristine: true,
1733-
errors: [],
1734-
errorMap: {},
1735-
}
1728+
acc[fieldKey] = defaultFieldMeta
17361729
return acc
17371730
},
17381731
{} as Record<TField, AnyFieldMeta>,
@@ -1969,15 +1962,7 @@ export class FormApi<
19691962
...prev,
19701963
fieldMetaBase: {
19711964
...prev.fieldMetaBase,
1972-
[field]: {
1973-
isValidating: false,
1974-
isTouched: false,
1975-
isBlurred: false,
1976-
isDirty: false,
1977-
isPristine: true,
1978-
errors: [],
1979-
errorMap: {},
1980-
},
1965+
[field]: defaultFieldMeta,
19811966
},
19821967
values: {
19831968
...prev.values,

packages/form-core/src/utils.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { GlobalFormValidationError, ValidationCause } from './types'
22
import type { FormValidators } from './FormApi'
3-
import type { FieldValidators } from './FieldApi'
3+
import type { AnyFieldMeta, FieldValidators } from './FieldApi'
44

55
export type UpdaterFn<TInput, TOutput = TInput> = (input: TInput) => TOutput
66

@@ -376,3 +376,13 @@ export function shallow<T>(objA: T, objB: T) {
376376
}
377377
return true
378378
}
379+
380+
export const defaultFieldMeta: AnyFieldMeta = {
381+
isValidating: false,
382+
isTouched: false,
383+
isBlurred: false,
384+
isDirty: false,
385+
isPristine: true,
386+
errors: [],
387+
errorMap: {},
388+
}

0 commit comments

Comments
 (0)