|
1 | | -import { createStore } from '@tanstack/store' |
| 1 | +import { batch, createStore } from '@tanstack/store' |
2 | 2 | import { |
3 | 3 | isStandardSchemaValidator, |
4 | 4 | standardSchemaValidators, |
|
8 | 8 | determineFieldLevelErrorSourceAndValue, |
9 | 9 | evaluate, |
10 | 10 | getAsyncValidatorArray, |
11 | | - getBy, |
12 | 11 | getSyncValidatorArray, |
13 | 12 | mergeOpts, |
14 | 13 | } from './utils' |
@@ -1322,6 +1321,9 @@ export class FieldApi< |
1322 | 1321 | value: this.state.value, |
1323 | 1322 | fieldApi: this, |
1324 | 1323 | }) |
| 1324 | + |
| 1325 | + // TODO: Remove |
| 1326 | + return () => {} |
1325 | 1327 | } |
1326 | 1328 |
|
1327 | 1329 | /** |
@@ -1622,62 +1624,62 @@ export class FieldApi< |
1622 | 1624 | // Needs type cast as eslint errantly believes this is always falsy |
1623 | 1625 | let hasErrored = false as boolean |
1624 | 1626 |
|
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 |
1631 | 1647 |
|
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] |
1645 | 1649 |
|
1646 | | - const formLevelError = errorFromForm[errorMapKey] |
| 1650 | + const { newErrorValue, newSource } = |
| 1651 | + determineFieldLevelErrorSourceAndValue({ |
| 1652 | + formLevelError, |
| 1653 | + fieldLevelError, |
| 1654 | + }) |
1647 | 1655 |
|
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 | + } |
1653 | 1674 |
|
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) |
1667 | 1677 | } |
1668 | | - if (newErrorValue) { |
1669 | | - hasErrored = true |
| 1678 | + for (const fieldValitateObj of linkedFieldValidates) { |
| 1679 | + if (!fieldValitateObj.validate) continue |
| 1680 | + validateFieldFn(fieldValitateObj.field, fieldValitateObj) |
1670 | 1681 | } |
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 | + }) |
1681 | 1683 |
|
1682 | 1684 | /** |
1683 | 1685 | * when we have an error for onSubmit in the state, we want |
|
0 commit comments