react-hook-form 7.44.0-next.0 → 7.44.0-next.1
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.
- package/dist/constants.d.ts +0 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/form.d.ts +13 -1
- package/dist/form.d.ts.map +1 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.mjs +59 -49
- package/dist/index.esm.mjs.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/logic/createFormControl.d.ts.map +1 -1
- package/dist/types/errors.d.ts +2 -2
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/form.d.ts +1 -1
- package/dist/types/form.d.ts.map +1 -1
- package/dist/utils/isMessage.d.ts.map +1 -1
- package/package.json +4 -7
package/dist/index.esm.mjs
CHANGED
@@ -59,8 +59,7 @@ const INPUT_VALIDATION_RULES = {
|
|
59
59
|
pattern: 'pattern',
|
60
60
|
required: 'required',
|
61
61
|
validate: 'validate',
|
62
|
-
};
|
63
|
-
const SERVER_ERROR_TYPE = 'root.server';
|
62
|
+
};
|
64
63
|
|
65
64
|
const HookFormContext = React__default.createContext(null);
|
66
65
|
/**
|
@@ -523,55 +522,69 @@ const POST_REQUEST = 'post';
|
|
523
522
|
function Form(props) {
|
524
523
|
const methods = useFormContext();
|
525
524
|
const [mounted, setMounted] = React.useState(false);
|
526
|
-
const { control = methods.control, onSubmit, children, action, method = POST_REQUEST, headers, encType, onError, render, onSuccess, validateStatus, ...rest } = props;
|
525
|
+
const { control = methods.control, onSubmit, children, action, method = POST_REQUEST, headers, encType, onError, render, onSuccess, validateStatus, fetcher, ...rest } = props;
|
527
526
|
const isPostRequest = method === POST_REQUEST;
|
528
|
-
const submit =
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
shouldStringifySubmissionData =
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
527
|
+
const submit = async (event) => {
|
528
|
+
let serverError = false;
|
529
|
+
await control.handleSubmit(async (values) => {
|
530
|
+
onSubmit && onSubmit(values);
|
531
|
+
if (action) {
|
532
|
+
const formData = new FormData();
|
533
|
+
let shouldStringifySubmissionData = false;
|
534
|
+
if (headers) {
|
535
|
+
shouldStringifySubmissionData =
|
536
|
+
headers['Content-Type'].includes('json');
|
537
|
+
}
|
538
|
+
else {
|
539
|
+
control._names.mount.forEach((name) => formData.append(name, get(values, name)));
|
540
|
+
}
|
541
|
+
if (!fetcher) {
|
542
|
+
try {
|
543
|
+
const response = await fetch(action, {
|
544
|
+
method,
|
545
|
+
headers: {
|
546
|
+
...headers,
|
547
|
+
...(encType ? { 'Content-Type': encType } : {}),
|
548
|
+
},
|
549
|
+
...(isPostRequest
|
550
|
+
? {
|
551
|
+
body: shouldStringifySubmissionData
|
552
|
+
? JSON.stringify(values)
|
553
|
+
: formData,
|
554
|
+
}
|
555
|
+
: {}),
|
556
|
+
});
|
557
|
+
if (response &&
|
558
|
+
(validateStatus
|
559
|
+
? !validateStatus(response.status)
|
560
|
+
: response.status < 200 || response.status >= 300)) {
|
561
|
+
serverError = true;
|
562
|
+
onError && onError({ response });
|
552
563
|
}
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
}
|
561
|
-
onError && onError({ response });
|
564
|
+
else {
|
565
|
+
onSuccess && onSuccess({ response });
|
566
|
+
}
|
567
|
+
}
|
568
|
+
catch (error) {
|
569
|
+
serverError = true;
|
570
|
+
onError && onError({ error });
|
571
|
+
}
|
562
572
|
}
|
563
573
|
else {
|
564
|
-
|
574
|
+
await fetcher(action, {
|
575
|
+
method,
|
576
|
+
values,
|
577
|
+
event,
|
578
|
+
});
|
565
579
|
}
|
566
580
|
}
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
}
|
573
|
-
|
574
|
-
});
|
581
|
+
})(event);
|
582
|
+
serverError &&
|
583
|
+
props.control &&
|
584
|
+
props.control._subjects.state.next({
|
585
|
+
isSubmitSuccessful: false,
|
586
|
+
});
|
587
|
+
};
|
575
588
|
React.useEffect(() => {
|
576
589
|
setMounted(true);
|
577
590
|
}, []);
|
@@ -688,7 +701,7 @@ var isHTMLElement = (value) => {
|
|
688
701
|
(owner && owner.defaultView ? owner.defaultView.HTMLElement : HTMLElement));
|
689
702
|
};
|
690
703
|
|
691
|
-
var isMessage = (value) => isString(value)
|
704
|
+
var isMessage = (value) => isString(value);
|
692
705
|
|
693
706
|
var isRadioInput = (element) => element.type === 'radio';
|
694
707
|
|
@@ -1950,9 +1963,6 @@ function createFormControl(props = {}, flushRootRender) {
|
|
1950
1963
|
name,
|
1951
1964
|
errors: _formState.errors,
|
1952
1965
|
isValid: false,
|
1953
|
-
...(error.type === SERVER_ERROR_TYPE
|
1954
|
-
? { isSubmitSuccessful: false }
|
1955
|
-
: {}),
|
1956
1966
|
});
|
1957
1967
|
options && options.shouldFocus && ref && ref.focus && ref.focus();
|
1958
1968
|
};
|