Skip to content

Commit b134a18

Browse files
committed
chore: fix various other issues
1 parent 85072f3 commit b134a18

8 files changed

Lines changed: 318 additions & 305 deletions

File tree

packages/form-core/src/FieldApi.ts

Lines changed: 54 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createStore } from '@tanstack/store'
1+
import { batch, createStore } from '@tanstack/store'
22
import {
33
isStandardSchemaValidator,
44
standardSchemaValidators,
@@ -8,7 +8,6 @@ import {
88
determineFieldLevelErrorSourceAndValue,
99
evaluate,
1010
getAsyncValidatorArray,
11-
getBy,
1211
getSyncValidatorArray,
1312
mergeOpts,
1413
} from './utils'
@@ -1322,6 +1321,9 @@ export class FieldApi<
13221321
value: this.state.value,
13231322
fieldApi: this,
13241323
})
1324+
1325+
// TODO: Remove
1326+
return () => {}
13251327
}
13261328

13271329
/**
@@ -1622,62 +1624,62 @@ export class FieldApi<
16221624
// Needs type cast as eslint errantly believes this is always falsy
16231625
let hasErrored = false as boolean
16241626

1625-
// batch(() => {
1626-
const validateFieldFn = (
1627-
field: AnyFieldApi,
1628-
validateObj: SyncValidator<any>,
1629-
) => {
1630-
const errorMapKey = getErrorMapKey(validateObj.cause)
1627+
batch(() => {
1628+
const validateFieldFn = (
1629+
field: AnyFieldApi,
1630+
validateObj: SyncValidator<any>,
1631+
) => {
1632+
const errorMapKey = getErrorMapKey(validateObj.cause)
1633+
1634+
const fieldLevelError = validateObj.validate
1635+
? normalizeError(
1636+
field.runValidator({
1637+
validate: validateObj.validate,
1638+
value: {
1639+
value: field.store.state.value,
1640+
validationSource: 'field',
1641+
fieldApi: field,
1642+
},
1643+
type: 'validate',
1644+
}),
1645+
)
1646+
: undefined
16311647

1632-
const fieldLevelError = validateObj.validate
1633-
? normalizeError(
1634-
field.runValidator({
1635-
validate: validateObj.validate,
1636-
value: {
1637-
value: field.store.state.value,
1638-
validationSource: 'field',
1639-
fieldApi: field,
1640-
},
1641-
type: 'validate',
1642-
}),
1643-
)
1644-
: undefined
1648+
const formLevelError = errorFromForm[errorMapKey]
16451649

1646-
const formLevelError = errorFromForm[errorMapKey]
1650+
const { newErrorValue, newSource } =
1651+
determineFieldLevelErrorSourceAndValue({
1652+
formLevelError,
1653+
fieldLevelError,
1654+
})
16471655

1648-
const { newErrorValue, newSource } =
1649-
determineFieldLevelErrorSourceAndValue({
1650-
formLevelError,
1651-
fieldLevelError,
1652-
})
1656+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
1657+
if (field.state.meta.errorMap?.[errorMapKey] !== newErrorValue) {
1658+
field.setMeta((prev) => ({
1659+
...prev,
1660+
errorMap: {
1661+
...prev.errorMap,
1662+
[errorMapKey]: newErrorValue,
1663+
},
1664+
errorSourceMap: {
1665+
...prev.errorSourceMap,
1666+
[errorMapKey]: newSource,
1667+
},
1668+
}))
1669+
}
1670+
if (newErrorValue) {
1671+
hasErrored = true
1672+
}
1673+
}
16531674

1654-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
1655-
if (field.state.meta.errorMap?.[errorMapKey] !== newErrorValue) {
1656-
field.setMeta((prev) => ({
1657-
...prev,
1658-
errorMap: {
1659-
...prev.errorMap,
1660-
[errorMapKey]: newErrorValue,
1661-
},
1662-
errorSourceMap: {
1663-
...prev.errorSourceMap,
1664-
[errorMapKey]: newSource,
1665-
},
1666-
}))
1675+
for (const validateObj of validates) {
1676+
validateFieldFn(this, validateObj)
16671677
}
1668-
if (newErrorValue) {
1669-
hasErrored = true
1678+
for (const fieldValitateObj of linkedFieldValidates) {
1679+
if (!fieldValitateObj.validate) continue
1680+
validateFieldFn(fieldValitateObj.field, fieldValitateObj)
16701681
}
1671-
}
1672-
1673-
for (const validateObj of validates) {
1674-
validateFieldFn(this, validateObj)
1675-
}
1676-
for (const fieldValitateObj of linkedFieldValidates) {
1677-
if (!fieldValitateObj.validate) continue
1678-
validateFieldFn(fieldValitateObj.field, fieldValitateObj)
1679-
}
1680-
// })
1682+
})
16811683

16821684
/**
16831685
* when we have an error for onSubmit in the state, we want

packages/form-core/src/FieldGroupApi.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createStore } from '@tanstack/store'
22
import { concatenatePaths, getBy, makePathArray } from './utils'
3-
import type { ReadonlyStore } from '@tanstack/store';
3+
import type { ReadonlyStore } from '@tanstack/store'
44
import type { Updater } from './utils'
55
import type {
66
FormApi,
@@ -303,7 +303,9 @@ export class FieldGroupApi<
303303
*
304304
* TODO: Remove
305305
*/
306-
mount = () => {}
306+
mount = () => {
307+
return () => {}
308+
}
307309

308310
/**
309311
* Validates the children of a specified array in the form starting from a given index until the end using the correct handlers for a given validation type.

0 commit comments

Comments
 (0)