react-hook-form 7.44.0-rc.4 → 7.44.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -556,7 +556,8 @@ function Form(props) {
556
556
  const [mounted, setMounted] = React.useState(false);
557
557
  const { control = methods.control, onSubmit, children, action, method = POST_REQUEST, headers, encType, onError, render, onSuccess, validateStatus, ...rest } = props;
558
558
  const submit = async (event) => {
559
- let serverError = false;
559
+ let hasError = false;
560
+ let type = '';
560
561
  await control.handleSubmit(async (data) => {
561
562
  const formData = new FormData();
562
563
  let formDataJson = '';
@@ -571,7 +572,6 @@ function Form(props) {
571
572
  onSubmit({
572
573
  data,
573
574
  event,
574
- action,
575
575
  method,
576
576
  formData,
577
577
  formDataJson,
@@ -579,7 +579,10 @@ function Form(props) {
579
579
  }
580
580
  if (action) {
581
581
  try {
582
- const shouldStringifySubmissionData = headers && headers['Content-Type'].includes('json');
582
+ const shouldStringifySubmissionData = [
583
+ headers && headers['Content-Type'],
584
+ encType,
585
+ ].includes('json');
583
586
  const response = await fetch(action, {
584
587
  method,
585
588
  headers: {
@@ -592,24 +595,28 @@ function Form(props) {
592
595
  (validateStatus
593
596
  ? !validateStatus(response.status)
594
597
  : response.status < 200 || response.status >= 300)) {
595
- serverError = true;
598
+ hasError = true;
596
599
  onError && onError({ response });
600
+ type = String(response.status);
597
601
  }
598
602
  else {
599
603
  onSuccess && onSuccess({ response });
600
604
  }
601
605
  }
602
606
  catch (error) {
603
- serverError = true;
607
+ hasError = true;
604
608
  onError && onError({ error });
605
609
  }
606
610
  }
607
611
  })(event);
608
- serverError &&
609
- props.control &&
612
+ if (hasError && props.control) {
610
613
  props.control._subjects.state.next({
611
614
  isSubmitSuccessful: false,
612
615
  });
616
+ props.control.setError('root.server', {
617
+ type,
618
+ });
619
+ }
613
620
  };
614
621
  React.useEffect(() => {
615
622
  setMounted(true);
@@ -879,7 +886,7 @@ var validateField = async (field, formValues, validateAllFieldCriteria, shouldUs
879
886
  }
880
887
  }
881
888
  }
882
- if (pattern && isString(inputValue)) {
889
+ if (pattern && !isEmpty && isString(inputValue)) {
883
890
  const { value: patternValue, message } = getValueAndMessage(pattern);
884
891
  if (isRegex(patternValue) && !inputValue.match(patternValue)) {
885
892
  error[name] = {