react-hook-form 7.39.5 → 7.39.6
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 +27 -22
- 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/dist/useFormContext.d.ts +1 -1
- package/dist/useFormContext.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/index.esm.mjs
CHANGED
@@ -122,10 +122,7 @@ const useFormContext = () => React.useContext(HookFormContext);
|
|
122
122
|
* }
|
123
123
|
* ```
|
124
124
|
*/
|
125
|
-
const FormProvider = (
|
126
|
-
const { children, ...data } = props;
|
127
|
-
return (React.createElement(HookFormContext.Provider, { value: data }, children));
|
128
|
-
};
|
125
|
+
const FormProvider = ({ children, ...data }) => (React.createElement(HookFormContext.Provider, { value: React.useState(data)[0] }, children));
|
129
126
|
|
130
127
|
var getProxyFormState = (formState, control, localProxyFormState, isRoot = true) => {
|
131
128
|
const result = {
|
@@ -263,7 +260,7 @@ var generateWatchOutput = (names, _names, formValues, isGlobal) => {
|
|
263
260
|
if (Array.isArray(names)) {
|
264
261
|
return names.map((fieldName) => (isGlobal && _names.watch.add(fieldName), get(formValues, fieldName)));
|
265
262
|
}
|
266
|
-
_names.watchAll =
|
263
|
+
isGlobal && (_names.watchAll = true);
|
267
264
|
return formValues;
|
268
265
|
};
|
269
266
|
|
@@ -1115,7 +1112,7 @@ function useFieldArray(props) {
|
|
1115
1112
|
values: control._formValues,
|
1116
1113
|
});
|
1117
1114
|
control._names.focus &&
|
1118
|
-
focusFieldBy(control._fields, (key) => !!key && key.startsWith(control._names.focus));
|
1115
|
+
focusFieldBy(control._fields, (key) => !!key && key.startsWith(control._names.focus || ''));
|
1119
1116
|
control._names.focus = '';
|
1120
1117
|
control._proxyFormState.isValid && control._updateValid();
|
1121
1118
|
}, [fields, name, control]);
|
@@ -1443,11 +1440,10 @@ function createFormControl(props = {}) {
|
|
1443
1440
|
timer = window.setTimeout(callback, wait);
|
1444
1441
|
};
|
1445
1442
|
const _updateValid = async () => {
|
1446
|
-
let isValid = false;
|
1447
1443
|
if (_proxyFormState.isValid) {
|
1448
|
-
isValid = _options.resolver
|
1444
|
+
const isValid = _options.resolver
|
1449
1445
|
? isEmptyObject((await _executeSchema()).errors)
|
1450
|
-
: await executeBuiltInValidation(_fields, true);
|
1446
|
+
: (await executeBuiltInValidation(_fields, true)).valid;
|
1451
1447
|
if (isValid !== _formState.isValid) {
|
1452
1448
|
_formState.isValid = isValid;
|
1453
1449
|
_subjects.state.next({
|
@@ -1455,7 +1451,6 @@ function createFormControl(props = {}) {
|
|
1455
1451
|
});
|
1456
1452
|
}
|
1457
1453
|
}
|
1458
|
-
return isValid;
|
1459
1454
|
};
|
1460
1455
|
const _updateFieldArray = (name, values = [], method, args, shouldSetValues = true, shouldUpdateFieldsAndState = true) => {
|
1461
1456
|
if (args && method) {
|
@@ -1480,6 +1475,7 @@ function createFormControl(props = {}) {
|
|
1480
1475
|
_formState.dirtyFields = getDirtyFields(_defaultValues, _formValues);
|
1481
1476
|
}
|
1482
1477
|
_subjects.state.next({
|
1478
|
+
name,
|
1483
1479
|
isDirty: _getDirty(name, values),
|
1484
1480
|
dirtyFields: _formState.dirtyFields,
|
1485
1481
|
errors: _formState.errors,
|
@@ -1583,9 +1579,7 @@ function createFormControl(props = {}) {
|
|
1583
1579
|
validateFields = {};
|
1584
1580
|
}
|
1585
1581
|
};
|
1586
|
-
const _executeSchema = async (name) => _options.resolver
|
1587
|
-
? await _options.resolver({ ..._formValues }, _options.context, getResolverOptions(name || _names.mount, _fields, _options.criteriaMode, _options.shouldUseNativeValidation))
|
1588
|
-
: {};
|
1582
|
+
const _executeSchema = async (name) => await _options.resolver(_formValues, _options.context, getResolverOptions(name || _names.mount, _fields, _options.criteriaMode, _options.shouldUseNativeValidation));
|
1589
1583
|
const executeSchemaAndUpdateState = async (names) => {
|
1590
1584
|
const { errors } = await _executeSchema();
|
1591
1585
|
if (names) {
|
@@ -1612,6 +1606,9 @@ function createFormControl(props = {}) {
|
|
1612
1606
|
const isFieldArrayRoot = _names.array.has(_f.name);
|
1613
1607
|
const fieldError = await validateField(field, get(_formValues, _f.name), shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation, isFieldArrayRoot);
|
1614
1608
|
if (fieldError[_f.name]) {
|
1609
|
+
if (_f.name === context.name) {
|
1610
|
+
context.error = fieldError[context.name];
|
1611
|
+
}
|
1615
1612
|
context.valid = false;
|
1616
1613
|
if (shouldOnlyCheckValid) {
|
1617
1614
|
break;
|
@@ -1628,7 +1625,7 @@ function createFormControl(props = {}) {
|
|
1628
1625
|
(await executeBuiltInValidation(fieldValue, shouldOnlyCheckValid, context));
|
1629
1626
|
}
|
1630
1627
|
}
|
1631
|
-
return context
|
1628
|
+
return context;
|
1632
1629
|
};
|
1633
1630
|
const _removeUnmounted = () => {
|
1634
1631
|
for (const name of _names.unMount) {
|
@@ -1795,8 +1792,17 @@ function createFormControl(props = {}) {
|
|
1795
1792
|
isValid = isEmptyObject(errors);
|
1796
1793
|
}
|
1797
1794
|
else {
|
1798
|
-
|
1799
|
-
|
1795
|
+
if (_proxyFormState.isValid) {
|
1796
|
+
const buildInValidationResult = await executeBuiltInValidation(_fields, true, {
|
1797
|
+
name,
|
1798
|
+
valid: true,
|
1799
|
+
});
|
1800
|
+
error = buildInValidationResult.error || {};
|
1801
|
+
isValid = buildInValidationResult.valid;
|
1802
|
+
}
|
1803
|
+
if (!error || isEmptyObject(error)) {
|
1804
|
+
error = (await validateField(field, get(_formValues, name), shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation))[name];
|
1805
|
+
}
|
1800
1806
|
}
|
1801
1807
|
field._f.deps &&
|
1802
1808
|
trigger(field._f.deps);
|
@@ -1820,12 +1826,13 @@ function createFormControl(props = {}) {
|
|
1820
1826
|
else if (name) {
|
1821
1827
|
validationResult = (await Promise.all(fieldNames.map(async (fieldName) => {
|
1822
1828
|
const field = get(_fields, fieldName);
|
1823
|
-
return await executeBuiltInValidation(field && field._f ? { [fieldName]: field } : field);
|
1829
|
+
return (await executeBuiltInValidation(field && field._f ? { [fieldName]: field } : field)).valid;
|
1824
1830
|
}))).every(Boolean);
|
1825
1831
|
!(!validationResult && !_formState.isValid) && _updateValid();
|
1826
1832
|
}
|
1827
1833
|
else {
|
1828
|
-
validationResult = isValid = await executeBuiltInValidation(_fields)
|
1834
|
+
validationResult = isValid = (await executeBuiltInValidation(_fields))
|
1835
|
+
.valid;
|
1829
1836
|
}
|
1830
1837
|
_subjects.state.next({
|
1831
1838
|
...(!isString(name) ||
|
@@ -1881,7 +1888,7 @@ function createFormControl(props = {}) {
|
|
1881
1888
|
};
|
1882
1889
|
const watch = (name, defaultValue) => isFunction(name)
|
1883
1890
|
? _subjects.watch.subscribe({
|
1884
|
-
next: (
|
1891
|
+
next: (payload) => name(_getWatch(undefined, defaultValue), payload),
|
1885
1892
|
})
|
1886
1893
|
: _getWatch(name, defaultValue, true);
|
1887
1894
|
const unregister = (name, options = {}) => {
|
@@ -1966,9 +1973,7 @@ function createFormControl(props = {}) {
|
|
1966
1973
|
refs: [
|
1967
1974
|
...refs.filter(live),
|
1968
1975
|
fieldRef,
|
1969
|
-
...(
|
1970
|
-
? [{}]
|
1971
|
-
: []),
|
1976
|
+
...(Array.isArray(get(_defaultValues, name)) ? [{}] : []),
|
1972
1977
|
],
|
1973
1978
|
ref: { type: fieldRef.type, name },
|
1974
1979
|
}
|