react-hook-form 7.52.2 → 7.53.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 +41 -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/logic/hasPromiseValidation.d.ts +4 -0
- package/dist/logic/hasPromiseValidation.d.ts.map +1 -0
- package/dist/logic/iterateFieldsByAction.d.ts +1 -1
- package/dist/logic/iterateFieldsByAction.d.ts.map +1 -1
- package/dist/types/path/common.d.ts +2 -2
- package/package.json +1 -1
package/dist/index.esm.mjs
CHANGED
@@ -693,20 +693,25 @@ const iterateFieldsByAction = (fields, action, fieldsNames, abortEarly) => {
|
|
693
693
|
const { _f, ...currentField } = field;
|
694
694
|
if (_f) {
|
695
695
|
if (_f.refs && _f.refs[0] && action(_f.refs[0], key) && !abortEarly) {
|
696
|
-
|
696
|
+
return true;
|
697
697
|
}
|
698
698
|
else if (_f.ref && action(_f.ref, _f.name) && !abortEarly) {
|
699
|
-
|
699
|
+
return true;
|
700
700
|
}
|
701
701
|
else {
|
702
|
-
iterateFieldsByAction(currentField, action)
|
702
|
+
if (iterateFieldsByAction(currentField, action)) {
|
703
|
+
break;
|
704
|
+
}
|
703
705
|
}
|
704
706
|
}
|
705
707
|
else if (isObject(currentField)) {
|
706
|
-
iterateFieldsByAction(currentField, action)
|
708
|
+
if (iterateFieldsByAction(currentField, action)) {
|
709
|
+
break;
|
710
|
+
}
|
707
711
|
}
|
708
712
|
}
|
709
713
|
}
|
714
|
+
return;
|
710
715
|
};
|
711
716
|
|
712
717
|
var updateFieldArrayRootError = (errors, error, name) => {
|
@@ -1466,6 +1471,13 @@ var getRuleValue = (rule) => isUndefined(rule)
|
|
1466
1471
|
: rule.value
|
1467
1472
|
: rule;
|
1468
1473
|
|
1474
|
+
const ASYNC_FUNCTION = 'AsyncFunction';
|
1475
|
+
var hasPromiseValidation = (fieldReference) => (!fieldReference || !fieldReference.validate) &&
|
1476
|
+
!!((isFunction(fieldReference.validate) &&
|
1477
|
+
fieldReference.validate.constructor.name === ASYNC_FUNCTION) ||
|
1478
|
+
(isObject(fieldReference.validate) &&
|
1479
|
+
Object.values(fieldReference.validate).find((validateFunction) => validateFunction.constructor.name === ASYNC_FUNCTION)));
|
1480
|
+
|
1469
1481
|
var hasValidation = (options) => options.mount &&
|
1470
1482
|
(options.required ||
|
1471
1483
|
options.min ||
|
@@ -1776,9 +1788,14 @@ function createFormControl(props = {}) {
|
|
1776
1788
|
const { _f, ...fieldValue } = field;
|
1777
1789
|
if (_f) {
|
1778
1790
|
const isFieldArrayRoot = _names.array.has(_f.name);
|
1779
|
-
|
1791
|
+
const isPromiseFunction = field._f && hasPromiseValidation(field._f);
|
1792
|
+
if (isPromiseFunction && _proxyFormState.validatingFields) {
|
1793
|
+
_updateIsValidating([name], true);
|
1794
|
+
}
|
1780
1795
|
const fieldError = await validateField(field, _formValues, shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation && !shouldOnlyCheckValid, isFieldArrayRoot);
|
1781
|
-
|
1796
|
+
if (isPromiseFunction && _proxyFormState.validatingFields) {
|
1797
|
+
_updateIsValidating([name]);
|
1798
|
+
}
|
1782
1799
|
if (fieldError[_f.name]) {
|
1783
1800
|
context.valid = false;
|
1784
1801
|
if (shouldOnlyCheckValid) {
|
@@ -1921,7 +1938,7 @@ function createFormControl(props = {}) {
|
|
1921
1938
|
const _updateIsFieldValueUpdated = (fieldValue) => {
|
1922
1939
|
isFieldValueUpdated =
|
1923
1940
|
Number.isNaN(fieldValue) ||
|
1924
|
-
fieldValue
|
1941
|
+
deepEqual(fieldValue, get(_formValues, name, fieldValue));
|
1925
1942
|
};
|
1926
1943
|
if (field) {
|
1927
1944
|
let error;
|
@@ -1951,7 +1968,16 @@ function createFormControl(props = {}) {
|
|
1951
1968
|
values: { ..._formValues },
|
1952
1969
|
});
|
1953
1970
|
if (shouldSkipValidation) {
|
1954
|
-
_proxyFormState.isValid
|
1971
|
+
if (_proxyFormState.isValid) {
|
1972
|
+
if (props.mode === 'onBlur') {
|
1973
|
+
if (isBlurEvent) {
|
1974
|
+
_updateValid();
|
1975
|
+
}
|
1976
|
+
}
|
1977
|
+
else {
|
1978
|
+
_updateValid();
|
1979
|
+
}
|
1980
|
+
}
|
1955
1981
|
return (shouldRender &&
|
1956
1982
|
_subjects.state.next({ name, ...(watched ? {} : fieldState) }));
|
1957
1983
|
}
|
@@ -2114,7 +2140,7 @@ function createFormControl(props = {}) {
|
|
2114
2140
|
};
|
2115
2141
|
const register = (name, options = {}) => {
|
2116
2142
|
let field = get(_fields, name);
|
2117
|
-
const disabledIsDefined = isBoolean(options.disabled);
|
2143
|
+
const disabledIsDefined = isBoolean(options.disabled) || isBoolean(props.disabled);
|
2118
2144
|
set(_fields, name, {
|
2119
2145
|
...(field || {}),
|
2120
2146
|
_f: {
|
@@ -2128,7 +2154,9 @@ function createFormControl(props = {}) {
|
|
2128
2154
|
if (field) {
|
2129
2155
|
_updateDisabledField({
|
2130
2156
|
field,
|
2131
|
-
disabled: options.disabled
|
2157
|
+
disabled: isBoolean(options.disabled)
|
2158
|
+
? options.disabled
|
2159
|
+
: props.disabled,
|
2132
2160
|
name,
|
2133
2161
|
value: options.value,
|
2134
2162
|
});
|
@@ -2137,7 +2165,9 @@ function createFormControl(props = {}) {
|
|
2137
2165
|
updateValidAndValue(name, true, options.value);
|
2138
2166
|
}
|
2139
2167
|
return {
|
2140
|
-
...(disabledIsDefined
|
2168
|
+
...(disabledIsDefined
|
2169
|
+
? { disabled: options.disabled || props.disabled }
|
2170
|
+
: {}),
|
2141
2171
|
...(_options.progressive
|
2142
2172
|
? {
|
2143
2173
|
required: !!options.required,
|