react-hook-form 7.44.0-rc.3 → 7.44.0-rc.5

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.
@@ -407,6 +407,7 @@ function useController(props) {
407
407
  ...props.rules,
408
408
  value,
409
409
  }));
410
+ _registerProps.current = control.register(name, props.rules);
410
411
  React__default.useEffect(() => {
411
412
  const _shouldUnregisterField = control._options.shouldUnregister || shouldUnregister;
412
413
  const updateMounted = (name, value) => {
@@ -545,7 +546,7 @@ const POST_REQUEST = 'post';
545
546
  * <input {...register("name")} />
546
547
  * <p>{errors?.root?.server && 'Server error'}</p>
547
548
  * <button>Submit</button>
548
- * </form>
549
+ * </Form>
549
550
  * );
550
551
  * }
551
552
  * ```
@@ -553,49 +554,49 @@ const POST_REQUEST = 'post';
553
554
  function Form(props) {
554
555
  const methods = useFormContext();
555
556
  const [mounted, setMounted] = React.useState(false);
556
- const { control = methods.control, onSubmit, children, action, method = POST_REQUEST, headers, encType, onError, render, onSuccess, validateStatus, fetcher, ...rest } = props;
557
+ const { control = methods.control, onSubmit, children, action, method = POST_REQUEST, headers, encType, onError, render, onSuccess, validateStatus, ...rest } = props;
557
558
  const submit = async (event) => {
558
559
  let serverError = false;
559
- await control.handleSubmit(async (values) => {
560
+ await control.handleSubmit(async (data) => {
560
561
  const formData = new FormData();
561
562
  let formDataJson = '';
562
563
  try {
563
- formDataJson = JSON.stringify(values);
564
+ formDataJson = JSON.stringify(data);
564
565
  }
565
566
  catch (_a) { }
566
- control._names.mount.forEach((name) => formData.append(name, get(values, name)));
567
- onSubmit && onSubmit(values);
567
+ for (const name of control._names.mount) {
568
+ formData.append(name, get(data, name));
569
+ }
570
+ if (onSubmit) {
571
+ onSubmit({
572
+ data,
573
+ event,
574
+ action,
575
+ method,
576
+ formData,
577
+ formDataJson,
578
+ });
579
+ }
568
580
  if (action) {
569
581
  try {
570
- if (fetcher) {
571
- await fetcher(action, {
572
- method,
573
- values,
574
- event,
575
- formData,
576
- formDataJson,
577
- });
582
+ const shouldStringifySubmissionData = headers && headers['Content-Type'].includes('json');
583
+ const response = await fetch(action, {
584
+ method,
585
+ headers: {
586
+ ...headers,
587
+ ...(encType ? { 'Content-Type': encType } : {}),
588
+ },
589
+ body: shouldStringifySubmissionData ? formDataJson : formData,
590
+ });
591
+ if (response &&
592
+ (validateStatus
593
+ ? !validateStatus(response.status)
594
+ : response.status < 200 || response.status >= 300)) {
595
+ serverError = true;
596
+ onError && onError({ response });
578
597
  }
579
598
  else {
580
- const shouldStringifySubmissionData = headers && headers['Content-Type'].includes('json');
581
- const response = await fetch(action, {
582
- method,
583
- headers: {
584
- ...headers,
585
- ...(encType ? { 'Content-Type': encType } : {}),
586
- },
587
- body: shouldStringifySubmissionData ? formDataJson : formData,
588
- });
589
- if (response &&
590
- (validateStatus
591
- ? !validateStatus(response.status)
592
- : response.status < 200 || response.status >= 300)) {
593
- serverError = true;
594
- onError && onError({ response });
595
- }
596
- else {
597
- onSuccess && onSuccess({ response });
598
- }
599
+ onSuccess && onSuccess({ response });
599
600
  }
600
601
  }
601
602
  catch (error) {
@@ -878,7 +879,7 @@ var validateField = async (field, formValues, validateAllFieldCriteria, shouldUs
878
879
  }
879
880
  }
880
881
  }
881
- if (pattern && isString(inputValue)) {
882
+ if (pattern && !isEmpty && isString(inputValue)) {
882
883
  const { value: patternValue, message } = getValueAndMessage(pattern);
883
884
  if (isRegex(patternValue) && !inputValue.match(patternValue)) {
884
885
  error[name] = {