@bombillazo/rhf-plus 7.56.3-plus.2 → 7.57.0-plus.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 +4 -4
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.mjs +33 -16
- 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/logic/schemaErrorLookup.d.ts.map +1 -1
- package/dist/logic/shouldSubscribeByName.d.ts +1 -1
- package/dist/logic/shouldSubscribeByName.d.ts.map +1 -1
- package/dist/react-server.esm.mjs +24 -10
- package/dist/react-server.esm.mjs.map +1 -1
- package/dist/types/form.d.ts +14 -10
- package/dist/types/form.d.ts.map +1 -1
- package/dist/useForm.d.ts.map +1 -1
- package/dist/useFormState.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.mjs
CHANGED
|
@@ -266,7 +266,7 @@ function useFormState(props) {
|
|
|
266
266
|
errors: false,
|
|
267
267
|
});
|
|
268
268
|
useIsomorphicLayoutEffect(() => control._subscribe({
|
|
269
|
-
name
|
|
269
|
+
name,
|
|
270
270
|
formState: _localProxyFormState.current,
|
|
271
271
|
exact,
|
|
272
272
|
callback: (formState) => {
|
|
@@ -319,7 +319,7 @@ function useWatch(props) {
|
|
|
319
319
|
const _defaultValue = React__default.useRef(defaultValue);
|
|
320
320
|
const [value, updateValue] = React__default.useState(control._getWatch(name, _defaultValue.current));
|
|
321
321
|
useIsomorphicLayoutEffect(() => control._subscribe({
|
|
322
|
-
name
|
|
322
|
+
name,
|
|
323
323
|
formState: {
|
|
324
324
|
values: true,
|
|
325
325
|
},
|
|
@@ -419,8 +419,8 @@ function useController(props) {
|
|
|
419
419
|
const field = get(control._fields, name);
|
|
420
420
|
if (field && elm) {
|
|
421
421
|
field._f.ref = {
|
|
422
|
-
focus: () => elm.focus(),
|
|
423
|
-
select: () => elm.select(),
|
|
422
|
+
focus: () => elm.focus && elm.focus(),
|
|
423
|
+
select: () => elm.select && elm.select(),
|
|
424
424
|
setCustomValidity: (message) => elm.setCustomValidity(message),
|
|
425
425
|
reportValidity: () => elm.reportValidity(),
|
|
426
426
|
};
|
|
@@ -1039,6 +1039,12 @@ function schemaErrorLookup(errors, _fields, name) {
|
|
|
1039
1039
|
error: foundError,
|
|
1040
1040
|
};
|
|
1041
1041
|
}
|
|
1042
|
+
if (foundError && foundError.root && foundError.root.type) {
|
|
1043
|
+
return {
|
|
1044
|
+
name: `${fieldName}.root`,
|
|
1045
|
+
error: foundError.root,
|
|
1046
|
+
};
|
|
1047
|
+
}
|
|
1042
1048
|
names.pop();
|
|
1043
1049
|
}
|
|
1044
1050
|
return {
|
|
@@ -1354,8 +1360,6 @@ function createFormControl(props = {}) {
|
|
|
1354
1360
|
array: createSubject(),
|
|
1355
1361
|
state: createSubject(),
|
|
1356
1362
|
};
|
|
1357
|
-
const validationModeBeforeSubmit = getValidationModes(_options.mode);
|
|
1358
|
-
const validationModeAfterSubmit = getValidationModes(_options.reValidateMode);
|
|
1359
1363
|
const shouldDisplayAllAssociatedErrors = _options.criteriaMode === VALIDATION_MODE.all;
|
|
1360
1364
|
const id = createId(props.id);
|
|
1361
1365
|
const debounce = (callback) => (wait) => {
|
|
@@ -1627,13 +1631,17 @@ function createFormControl(props = {}) {
|
|
|
1627
1631
|
}
|
|
1628
1632
|
else if (fieldReference.refs) {
|
|
1629
1633
|
if (isCheckBoxInput(fieldReference.ref)) {
|
|
1630
|
-
fieldReference.refs.
|
|
1631
|
-
|
|
1632
|
-
(
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1634
|
+
fieldReference.refs.forEach((checkboxRef) => {
|
|
1635
|
+
if (!checkboxRef.defaultChecked || !checkboxRef.disabled) {
|
|
1636
|
+
if (Array.isArray(fieldValue)) {
|
|
1637
|
+
checkboxRef.checked = !!fieldValue.find((data) => data === checkboxRef.value);
|
|
1638
|
+
}
|
|
1639
|
+
else {
|
|
1640
|
+
checkboxRef.checked =
|
|
1641
|
+
fieldValue === checkboxRef.value || !!fieldValue;
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
});
|
|
1637
1645
|
}
|
|
1638
1646
|
else {
|
|
1639
1647
|
fieldReference.refs.forEach((radioRef) => (radioRef.checked = radioRef.value === fieldValue));
|
|
@@ -1659,8 +1667,11 @@ function createFormControl(props = {}) {
|
|
|
1659
1667
|
};
|
|
1660
1668
|
const setValues = (name, value, options) => {
|
|
1661
1669
|
for (const fieldKey in value) {
|
|
1670
|
+
if (!value.hasOwnProperty(fieldKey)) {
|
|
1671
|
+
return;
|
|
1672
|
+
}
|
|
1662
1673
|
const fieldValue = value[fieldKey];
|
|
1663
|
-
const fieldName =
|
|
1674
|
+
const fieldName = name + '.' + fieldKey;
|
|
1664
1675
|
const field = get(_fields, fieldName);
|
|
1665
1676
|
(_names.array.has(name) ||
|
|
1666
1677
|
isObject(fieldValue) ||
|
|
@@ -1715,6 +1726,8 @@ function createFormControl(props = {}) {
|
|
|
1715
1726
|
(isDateObject(fieldValue) && isNaN(fieldValue.getTime())) ||
|
|
1716
1727
|
deepEqual(fieldValue, get(_formValues, name, fieldValue));
|
|
1717
1728
|
};
|
|
1729
|
+
const validationModeBeforeSubmit = getValidationModes(_options.mode);
|
|
1730
|
+
const validationModeAfterSubmit = getValidationModes(_options.reValidateMode);
|
|
1718
1731
|
if (field) {
|
|
1719
1732
|
let error;
|
|
1720
1733
|
let isValid;
|
|
@@ -2300,6 +2313,7 @@ function createFormControl(props = {}) {
|
|
|
2300
2313
|
setError,
|
|
2301
2314
|
_subscribe,
|
|
2302
2315
|
_runSchema,
|
|
2316
|
+
_focusError,
|
|
2303
2317
|
_getWatch,
|
|
2304
2318
|
_getDirty,
|
|
2305
2319
|
_setValid,
|
|
@@ -2771,10 +2785,13 @@ function useForm(props = {}) {
|
|
|
2771
2785
|
if (props.reValidateMode) {
|
|
2772
2786
|
control._options.reValidateMode = props.reValidateMode;
|
|
2773
2787
|
}
|
|
2774
|
-
|
|
2788
|
+
}, [control, props.mode, props.reValidateMode]);
|
|
2789
|
+
React__default.useEffect(() => {
|
|
2790
|
+
if (props.errors) {
|
|
2775
2791
|
control._setErrors(props.errors);
|
|
2792
|
+
control._focusError();
|
|
2776
2793
|
}
|
|
2777
|
-
}, [control, props.errors
|
|
2794
|
+
}, [control, props.errors]);
|
|
2778
2795
|
React__default.useEffect(() => {
|
|
2779
2796
|
props.shouldUnregister &&
|
|
2780
2797
|
control._subjects.state.next({
|