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

Function validateForm

src/logic/createFormControl.ts:579–618  ·  view source on GitHub ↗
({
    name,
    eventType,
  }: {
    name: FieldPath<TFieldValues> | FieldPath<TFieldValues>[] | undefined;
    eventType: ValidateFormEventType;
  })

Source from the content-addressed store, hash-verified

577 };
578
579 const validateForm = async ({
580 name,
581 eventType,
582 }: {
583 name: FieldPath<TFieldValues> | FieldPath<TFieldValues>[] | undefined;
584 eventType: ValidateFormEventType;
585 }) => {
586 if (props.validate) {
587 const result = await props.validate({
588 formValues: _formValues,
589 formState: _formState,
590 name,
591 eventType,
592 });
593
594 if (isObject(result)) {
595 for (const key in result) {
596 const error = result[key];
597
598 if (error) {
599 setError(`${FORM_ERROR_TYPE}.${key}`, {
600 message: isString(error.message) ? error.message : '',
601 type: error.type || INPUT_VALIDATION_RULES.validate,
602 });
603 }
604 }
605 } else if (isString(result) || !result) {
606 setError(FORM_ERROR_TYPE, {
607 message: result || '',
608 type: INPUT_VALIDATION_RULES.validate,
609 });
610 } else {
611 clearErrors(FORM_ERROR_TYPE);
612 }
613
614 return result;
615 }
616
617 return true;
618 };
619
620 const executeBuiltInValidation = async ({
621 fields,

Callers 2

executeBuiltInValidationFunction · 0.85
onChangeFunction · 0.85

Calls 2

setErrorFunction · 0.85
clearErrorsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…