MCPcopy Create free account
hub / github.com/react-hook-form/react-hook-form / validateForm

Function validateForm

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

Source from the content-addressed store, hash-verified

494 };
495
496 const validateForm = async ({
497 name,
498 eventType,
499 }: {
500 name: FieldPath<TFieldValues> | FieldPath<TFieldValues>[] | undefined;
501 eventType: ValidateFormEventType;
502 }) => {
503 if (props.validate) {
504 const result = await props.validate({
505 formValues: _formValues,
506 formState: _formState,
507 name,
508 eventType,
509 });
510
511 if (isObject(result)) {
512 for (const key in result) {
513 const error = result[key];
514
515 if (error) {
516 setError(`${FORM_ERROR_TYPE}.${key}`, {
517 message: isString(result.message) ? result.message : '',
518 type: INPUT_VALIDATION_RULES.validate,
519 });
520 }
521 }
522 } else if (isString(result) || !result) {
523 setError(FORM_ERROR_TYPE, {
524 message: result || '',
525 type: INPUT_VALIDATION_RULES.validate,
526 });
527 } else {
528 clearErrors(FORM_ERROR_TYPE);
529 }
530
531 return result;
532 }
533
534 return true;
535 };
536
537 const executeBuiltInValidation = async ({
538 fields,

Callers 2

executeBuiltInValidationFunction · 0.85
onChangeFunction · 0.85

Calls 2

setErrorFunction · 0.85
clearErrorsFunction · 0.85

Tested by

no test coverage detected