({
newFormValidatorError,
isPreviousErrorFromFormValidator,
previousErrorValue,
}: {
newFormValidatorError: ValidationError
isPreviousErrorFromFormValidator: boolean
previousErrorValue: ValidationError
})
| 477 | * @private |
| 478 | */ |
| 479 | export 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. |
no outgoing calls
no test coverage detected