react-hook-form 7.44.0-rc.3 → 7.44.0-rc.4
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 +3 -0
- package/dist/form.d.ts +6 -12
- 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 +34 -33
- 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 +8 -0
- package/dist/types/form.d.ts.map +1 -1
- package/dist/useController.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.mjs
CHANGED
@@ -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
|
-
* </
|
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,
|
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 (
|
560
|
+
await control.handleSubmit(async (data) => {
|
560
561
|
const formData = new FormData();
|
561
562
|
let formDataJson = '';
|
562
563
|
try {
|
563
|
-
formDataJson = JSON.stringify(
|
564
|
+
formDataJson = JSON.stringify(data);
|
564
565
|
}
|
565
566
|
catch (_a) { }
|
566
|
-
control._names.mount
|
567
|
-
|
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
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
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
|
-
|
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) {
|