react-hook-form 7.39.5 → 7.39.7
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/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.mjs +26 -18
- 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/getProxyFormState.d.ts +1 -1
- package/dist/logic/getProxyFormState.d.ts.map +1 -1
- package/dist/types/form.d.ts +2 -2
- package/dist/types/form.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/index.esm.mjs
CHANGED
@@ -263,7 +263,7 @@ var generateWatchOutput = (names, _names, formValues, isGlobal) => {
|
|
263
263
|
if (Array.isArray(names)) {
|
264
264
|
return names.map((fieldName) => (isGlobal && _names.watch.add(fieldName), get(formValues, fieldName)));
|
265
265
|
}
|
266
|
-
_names.watchAll =
|
266
|
+
isGlobal && (_names.watchAll = true);
|
267
267
|
return formValues;
|
268
268
|
};
|
269
269
|
|
@@ -1115,7 +1115,7 @@ function useFieldArray(props) {
|
|
1115
1115
|
values: control._formValues,
|
1116
1116
|
});
|
1117
1117
|
control._names.focus &&
|
1118
|
-
focusFieldBy(control._fields, (key) => !!key && key.startsWith(control._names.focus));
|
1118
|
+
focusFieldBy(control._fields, (key) => !!key && key.startsWith(control._names.focus || ''));
|
1119
1119
|
control._names.focus = '';
|
1120
1120
|
control._proxyFormState.isValid && control._updateValid();
|
1121
1121
|
}, [fields, name, control]);
|
@@ -1443,11 +1443,10 @@ function createFormControl(props = {}) {
|
|
1443
1443
|
timer = window.setTimeout(callback, wait);
|
1444
1444
|
};
|
1445
1445
|
const _updateValid = async () => {
|
1446
|
-
let isValid = false;
|
1447
1446
|
if (_proxyFormState.isValid) {
|
1448
|
-
isValid = _options.resolver
|
1447
|
+
const isValid = _options.resolver
|
1449
1448
|
? isEmptyObject((await _executeSchema()).errors)
|
1450
|
-
: await executeBuiltInValidation(_fields, true);
|
1449
|
+
: (await executeBuiltInValidation(_fields, true)).valid;
|
1451
1450
|
if (isValid !== _formState.isValid) {
|
1452
1451
|
_formState.isValid = isValid;
|
1453
1452
|
_subjects.state.next({
|
@@ -1455,7 +1454,6 @@ function createFormControl(props = {}) {
|
|
1455
1454
|
});
|
1456
1455
|
}
|
1457
1456
|
}
|
1458
|
-
return isValid;
|
1459
1457
|
};
|
1460
1458
|
const _updateFieldArray = (name, values = [], method, args, shouldSetValues = true, shouldUpdateFieldsAndState = true) => {
|
1461
1459
|
if (args && method) {
|
@@ -1480,6 +1478,7 @@ function createFormControl(props = {}) {
|
|
1480
1478
|
_formState.dirtyFields = getDirtyFields(_defaultValues, _formValues);
|
1481
1479
|
}
|
1482
1480
|
_subjects.state.next({
|
1481
|
+
name,
|
1483
1482
|
isDirty: _getDirty(name, values),
|
1484
1483
|
dirtyFields: _formState.dirtyFields,
|
1485
1484
|
errors: _formState.errors,
|
@@ -1583,9 +1582,7 @@ function createFormControl(props = {}) {
|
|
1583
1582
|
validateFields = {};
|
1584
1583
|
}
|
1585
1584
|
};
|
1586
|
-
const _executeSchema = async (name) => _options.resolver
|
1587
|
-
? await _options.resolver({ ..._formValues }, _options.context, getResolverOptions(name || _names.mount, _fields, _options.criteriaMode, _options.shouldUseNativeValidation))
|
1588
|
-
: {};
|
1585
|
+
const _executeSchema = async (name) => await _options.resolver(_formValues, _options.context, getResolverOptions(name || _names.mount, _fields, _options.criteriaMode, _options.shouldUseNativeValidation));
|
1589
1586
|
const executeSchemaAndUpdateState = async (names) => {
|
1590
1587
|
const { errors } = await _executeSchema();
|
1591
1588
|
if (names) {
|
@@ -1612,6 +1609,9 @@ function createFormControl(props = {}) {
|
|
1612
1609
|
const isFieldArrayRoot = _names.array.has(_f.name);
|
1613
1610
|
const fieldError = await validateField(field, get(_formValues, _f.name), shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation, isFieldArrayRoot);
|
1614
1611
|
if (fieldError[_f.name]) {
|
1612
|
+
if (_f.name === context.name) {
|
1613
|
+
context.error = fieldError[context.name];
|
1614
|
+
}
|
1615
1615
|
context.valid = false;
|
1616
1616
|
if (shouldOnlyCheckValid) {
|
1617
1617
|
break;
|
@@ -1628,7 +1628,7 @@ function createFormControl(props = {}) {
|
|
1628
1628
|
(await executeBuiltInValidation(fieldValue, shouldOnlyCheckValid, context));
|
1629
1629
|
}
|
1630
1630
|
}
|
1631
|
-
return context
|
1631
|
+
return context;
|
1632
1632
|
};
|
1633
1633
|
const _removeUnmounted = () => {
|
1634
1634
|
for (const name of _names.unMount) {
|
@@ -1795,8 +1795,17 @@ function createFormControl(props = {}) {
|
|
1795
1795
|
isValid = isEmptyObject(errors);
|
1796
1796
|
}
|
1797
1797
|
else {
|
1798
|
-
|
1799
|
-
|
1798
|
+
if (_proxyFormState.isValid) {
|
1799
|
+
const buildInValidationResult = await executeBuiltInValidation(_fields, true, {
|
1800
|
+
name,
|
1801
|
+
valid: true,
|
1802
|
+
});
|
1803
|
+
error = buildInValidationResult.error || {};
|
1804
|
+
isValid = buildInValidationResult.valid;
|
1805
|
+
}
|
1806
|
+
if (!error || isEmptyObject(error)) {
|
1807
|
+
error = (await validateField(field, get(_formValues, name), shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation))[name];
|
1808
|
+
}
|
1800
1809
|
}
|
1801
1810
|
field._f.deps &&
|
1802
1811
|
trigger(field._f.deps);
|
@@ -1820,12 +1829,13 @@ function createFormControl(props = {}) {
|
|
1820
1829
|
else if (name) {
|
1821
1830
|
validationResult = (await Promise.all(fieldNames.map(async (fieldName) => {
|
1822
1831
|
const field = get(_fields, fieldName);
|
1823
|
-
return await executeBuiltInValidation(field && field._f ? { [fieldName]: field } : field);
|
1832
|
+
return (await executeBuiltInValidation(field && field._f ? { [fieldName]: field } : field)).valid;
|
1824
1833
|
}))).every(Boolean);
|
1825
1834
|
!(!validationResult && !_formState.isValid) && _updateValid();
|
1826
1835
|
}
|
1827
1836
|
else {
|
1828
|
-
validationResult = isValid = await executeBuiltInValidation(_fields)
|
1837
|
+
validationResult = isValid = (await executeBuiltInValidation(_fields))
|
1838
|
+
.valid;
|
1829
1839
|
}
|
1830
1840
|
_subjects.state.next({
|
1831
1841
|
...(!isString(name) ||
|
@@ -1881,7 +1891,7 @@ function createFormControl(props = {}) {
|
|
1881
1891
|
};
|
1882
1892
|
const watch = (name, defaultValue) => isFunction(name)
|
1883
1893
|
? _subjects.watch.subscribe({
|
1884
|
-
next: (
|
1894
|
+
next: (payload) => name(_getWatch(undefined, defaultValue), payload),
|
1885
1895
|
})
|
1886
1896
|
: _getWatch(name, defaultValue, true);
|
1887
1897
|
const unregister = (name, options = {}) => {
|
@@ -1966,9 +1976,7 @@ function createFormControl(props = {}) {
|
|
1966
1976
|
refs: [
|
1967
1977
|
...refs.filter(live),
|
1968
1978
|
fieldRef,
|
1969
|
-
...(
|
1970
|
-
? [{}]
|
1971
|
-
: []),
|
1979
|
+
...(Array.isArray(get(_defaultValues, name)) ? [{}] : []),
|
1972
1980
|
],
|
1973
1981
|
ref: { type: fieldRef.type, name },
|
1974
1982
|
}
|