MCPcopy
hub / github.com/react-hook-form/react-hook-form / executeBuiltInValidation

Function executeBuiltInValidation

src/logic/createFormControl.ts:620–724  ·  view source on GitHub ↗
({
    fields,
    onlyCheckValid,
    name,
    eventType,
    context = {
      valid: true,
      runRootValidation: false,
    },
  }: {
    fields: FieldRefs;
    onlyCheckValid?: boolean;
    name?: FieldPath<TFieldValues> | FieldPath<TFieldValues>[];
    eventType: ValidateFormEventType;
    context?: {
      valid: boolean;
      runRootValidation?: boolean;
    };
  })

Source from the content-addressed store, hash-verified

618 };
619
620 const executeBuiltInValidation = async ({
621 fields,
622 onlyCheckValid,
623 name,
624 eventType,
625 context = {
626 valid: true,
627 runRootValidation: false,
628 },
629 }: {
630 fields: FieldRefs;
631 onlyCheckValid?: boolean;
632 name?: FieldPath<TFieldValues> | FieldPath<TFieldValues>[];
633 eventType: ValidateFormEventType;
634 context?: {
635 valid: boolean;
636 runRootValidation?: boolean;
637 };
638 }) => {
639 if (props.validate) {
640 context.runRootValidation = true;
641 const result = await validateForm({
642 name,
643 eventType,
644 });
645
646 if (!result) {
647 context.valid = false;
648
649 if (onlyCheckValid) {
650 return context.valid;
651 }
652 }
653 }
654
655 for (const name in fields) {
656 const field = fields[name];
657
658 if (field) {
659 const { _f, ...fieldValue } = field as Field;
660
661 if (_f) {
662 const isFieldArrayRoot = _names.array.has(_f.name);
663 const isPromiseFunction =
664 field._f && hasPromiseValidation((field as Field)._f);
665 const shouldTrackIsValidatingState =
666 _proxyFormState.validatingFields ||
667 _proxyFormState.isValidating ||
668 _proxySubscribeFormState.validatingFields ||
669 _proxySubscribeFormState.isValidating;
670
671 if (isPromiseFunction && shouldTrackIsValidatingState) {
672 _updateIsValidating([_f.name], true);
673 }
674
675 const fieldError = await validateField(
676 field as Field,
677 _names.disabled,

Callers 4

_setValidFunction · 0.85
onChangeFunction · 0.85
triggerFunction · 0.85
handleSubmitFunction · 0.85

Calls 3

validateFormFunction · 0.85
_updateIsValidatingFunction · 0.85
unsetFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…