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.
- package/README.md +6 -0
- package/dist/form.d.ts +14 -20
- 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 +15 -8
- 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/types/form.d.ts +0 -1
- package/dist/types/form.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.mjs
CHANGED
@@ -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
|
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 =
|
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
|
-
|
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
|
-
|
607
|
+
hasError = true;
|
604
608
|
onError && onError({ error });
|
605
609
|
}
|
606
610
|
}
|
607
611
|
})(event);
|
608
|
-
|
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] = {
|