react-hook-form 7.31.3 → 7.32.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 +3 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.mjs +19 -11
- 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/form.d.ts +5 -5
- package/dist/types/form.d.ts.map +1 -1
- package/dist/utils/cloneObject.d.ts.map +1 -1
- package/dist/utils/isHTMLElement.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.mjs
CHANGED
@@ -575,7 +575,11 @@ function cloneObject(data) {
|
|
575
575
|
(isArray || isObject(data))) {
|
576
576
|
copy = isArray ? [] : {};
|
577
577
|
for (const key in data) {
|
578
|
-
|
578
|
+
if (isFunction(data[key])) {
|
579
|
+
copy = data;
|
580
|
+
break;
|
581
|
+
}
|
582
|
+
copy[key] = cloneObject(data[key]);
|
579
583
|
}
|
580
584
|
}
|
581
585
|
else {
|
@@ -938,7 +942,11 @@ var isBoolean = (value) => typeof value === 'boolean';
|
|
938
942
|
|
939
943
|
var isFileInput = (element) => element.type === 'file';
|
940
944
|
|
941
|
-
var isHTMLElement = (value) =>
|
945
|
+
var isHTMLElement = (value) => {
|
946
|
+
const owner = value ? value.ownerDocument : 0;
|
947
|
+
const ElementClass = owner && owner.defaultView ? owner.defaultView.HTMLElement : HTMLElement;
|
948
|
+
return value instanceof ElementClass;
|
949
|
+
};
|
942
950
|
|
943
951
|
var isMultipleSelect = (element) => element.type === `select-multiple`;
|
944
952
|
|
@@ -1378,9 +1386,9 @@ function createFormControl(props = {}) {
|
|
1378
1386
|
const validationModeBeforeSubmit = getValidationModes(_options.mode);
|
1379
1387
|
const validationModeAfterSubmit = getValidationModes(_options.reValidateMode);
|
1380
1388
|
const shouldDisplayAllAssociatedErrors = _options.criteriaMode === VALIDATION_MODE.all;
|
1381
|
-
const debounce = (callback
|
1389
|
+
const debounce = (callback) => (wait) => {
|
1382
1390
|
clearTimeout(timer);
|
1383
|
-
timer = window.setTimeout(
|
1391
|
+
timer = window.setTimeout(callback, wait);
|
1384
1392
|
};
|
1385
1393
|
const _updateValid = async (shouldSkipRender) => {
|
1386
1394
|
let isValid = false;
|
@@ -1480,13 +1488,13 @@ function createFormControl(props = {}) {
|
|
1480
1488
|
isFieldDirty && shouldRender && _subjects.state.next(output);
|
1481
1489
|
return isFieldDirty ? output : {};
|
1482
1490
|
};
|
1483
|
-
const shouldRenderByError = async (
|
1491
|
+
const shouldRenderByError = async (name, isValid, error, fieldState) => {
|
1484
1492
|
const previousFieldError = get(_formState.errors, name);
|
1485
1493
|
const shouldUpdateValid = _proxyFormState.isValid && _formState.isValid !== isValid;
|
1486
1494
|
if (props.delayError && error) {
|
1487
1495
|
delayErrorCallback =
|
1488
|
-
delayErrorCallback || debounce(updateErrors,
|
1489
|
-
delayErrorCallback(
|
1496
|
+
delayErrorCallback || debounce(() => updateErrors(name, error));
|
1497
|
+
delayErrorCallback(props.delayError);
|
1490
1498
|
}
|
1491
1499
|
else {
|
1492
1500
|
clearTimeout(timer);
|
@@ -1494,10 +1502,9 @@ function createFormControl(props = {}) {
|
|
1494
1502
|
? set(_formState.errors, name, error)
|
1495
1503
|
: unset(_formState.errors, name);
|
1496
1504
|
}
|
1497
|
-
if ((
|
1505
|
+
if ((error ? !deepEqual(previousFieldError, error) : previousFieldError) ||
|
1498
1506
|
!isEmptyObject(fieldState) ||
|
1499
|
-
shouldUpdateValid)
|
1500
|
-
!shouldSkipRender) {
|
1507
|
+
shouldUpdateValid) {
|
1501
1508
|
const updatedFormState = {
|
1502
1509
|
...fieldState,
|
1503
1510
|
...(shouldUpdateValid ? { isValid } : {}),
|
@@ -1699,6 +1706,7 @@ function createFormControl(props = {}) {
|
|
1699
1706
|
set(_formValues, name, fieldValue);
|
1700
1707
|
if (isBlurEvent) {
|
1701
1708
|
field._f.onBlur && field._f.onBlur(event);
|
1709
|
+
delayErrorCallback && delayErrorCallback(0);
|
1702
1710
|
}
|
1703
1711
|
else if (field._f.onChange) {
|
1704
1712
|
field._f.onChange(event);
|
@@ -1733,7 +1741,7 @@ function createFormControl(props = {}) {
|
|
1733
1741
|
}
|
1734
1742
|
field._f.deps &&
|
1735
1743
|
trigger(field._f.deps);
|
1736
|
-
shouldRenderByError(
|
1744
|
+
shouldRenderByError(name, isValid, error, fieldState);
|
1737
1745
|
}
|
1738
1746
|
};
|
1739
1747
|
const trigger = async (name, options = {}) => {
|