MCPcopy Index your code
hub / github.com/TanStack/form / determineFormLevelErrorSourceAndValue

Function determineFormLevelErrorSourceAndValue

packages/form-core/src/utils.ts:479–508  ·  view source on GitHub ↗
({
  newFormValidatorError,
  isPreviousErrorFromFormValidator,
  previousErrorValue,
}: {
  newFormValidatorError: ValidationError
  isPreviousErrorFromFormValidator: boolean
  previousErrorValue: ValidationError
})

Source from the content-addressed store, hash-verified

477 * @private
478 */
479export const determineFormLevelErrorSourceAndValue = ({
480 newFormValidatorError,
481 isPreviousErrorFromFormValidator,
482 previousErrorValue,
483}: {
484 newFormValidatorError: ValidationError
485 isPreviousErrorFromFormValidator: boolean
486 previousErrorValue: ValidationError
487}): {
488 newErrorValue: ValidationError
489 newSource: ValidationSource | undefined
490} => {
491 // All falsy values are not considered errors
492 if (newFormValidatorError) {
493 return { newErrorValue: newFormValidatorError, newSource: 'form' }
494 }
495
496 // Clears form level error since it's now stale
497 if (isPreviousErrorFromFormValidator) {
498 return { newErrorValue: undefined, newSource: undefined }
499 }
500
501 // At this point, we have a preivous error which must have been set by the field validator, keep as is
502 if (previousErrorValue) {
503 return { newErrorValue: previousErrorValue, newSource: 'field' }
504 }
505
506 // No new or previous error, clear the error
507 return { newErrorValue: undefined, newSource: undefined }
508}
509
510/**
511 * Determines the logic for determining the error source and value to set on the field meta within the field level sync/async validation.

Callers 2

FormApiClass · 0.90
utils.spec.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected