react-hook-form 7.28.1 → 7.29.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 +0 -3
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.mjs +171 -81
- 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/focusFieldBy.d.ts.map +1 -1
- package/dist/logic/shouldRenderFormState.d.ts.map +1 -1
- package/dist/useFormContext.d.ts.map +1 -1
- package/dist/utils/compact.d.ts.map +1 -1
- package/package.json +2 -2
- package/dist/utils/omitKeys.d.ts +0 -3
- package/dist/utils/omitKeys.d.ts.map +0 -1
package/dist/index.esm.mjs
CHANGED
@@ -22,7 +22,7 @@ var getNodeParentName = (name) => name.substring(0, name.search(/.\d/)) || name;
|
|
22
22
|
|
23
23
|
var isNameInFieldArray = (names, name) => [...names].some((current) => getNodeParentName(name) === current);
|
24
24
|
|
25
|
-
var compact = (value) => value.filter(Boolean);
|
25
|
+
var compact = (value) => Array.isArray(value) ? value.filter(Boolean) : [];
|
26
26
|
|
27
27
|
var isUndefined = (val) => val === undefined;
|
28
28
|
|
@@ -60,12 +60,6 @@ const INPUT_VALIDATION_RULES = {
|
|
60
60
|
validate: 'validate',
|
61
61
|
};
|
62
62
|
|
63
|
-
var omit = (source, key) => {
|
64
|
-
const copy = Object.assign({}, source);
|
65
|
-
delete copy[key];
|
66
|
-
return copy;
|
67
|
-
};
|
68
|
-
|
69
63
|
const HookFormContext = React.createContext(null);
|
70
64
|
/**
|
71
65
|
* This custom hook allows you to access the form context. useFormContext is intended to be used in deeply nested structures, where it would become inconvenient to pass the context as a prop. To be used with {@link FormProvider}.
|
@@ -128,7 +122,10 @@ const useFormContext = () => React.useContext(HookFormContext);
|
|
128
122
|
* }
|
129
123
|
* ```
|
130
124
|
*/
|
131
|
-
const FormProvider = (props) =>
|
125
|
+
const FormProvider = (props) => {
|
126
|
+
const { children, ...data } = props;
|
127
|
+
return (React.createElement(HookFormContext.Provider, { value: data }, props.children));
|
128
|
+
};
|
132
129
|
|
133
130
|
var getProxyFormState = (formState, _proxyFormState, localProxyFormState, isRoot = true) => {
|
134
131
|
const result = {};
|
@@ -150,7 +147,7 @@ var getProxyFormState = (formState, _proxyFormState, localProxyFormState, isRoot
|
|
150
147
|
var isEmptyObject = (value) => isObject(value) && !Object.keys(value).length;
|
151
148
|
|
152
149
|
var shouldRenderFormState = (formStateData, _proxyFormState, isRoot) => {
|
153
|
-
const formState =
|
150
|
+
const { name, ...formState } = formStateData;
|
154
151
|
return (isEmptyObject(formState) ||
|
155
152
|
Object.keys(formState).length >= Object.keys(_proxyFormState).length ||
|
156
153
|
Object.keys(formState).find((key) => _proxyFormState[key] ===
|
@@ -233,14 +230,20 @@ function useFormState(props) {
|
|
233
230
|
const callback = React.useCallback((value) => _mounted.current &&
|
234
231
|
shouldSubscribeByName(_name.current, value.name, exact) &&
|
235
232
|
shouldRenderFormState(value, _localProxyFormState.current) &&
|
236
|
-
updateFormState(
|
233
|
+
updateFormState({
|
234
|
+
...control._formState,
|
235
|
+
...value,
|
236
|
+
}), [control, exact]);
|
237
237
|
useSubscribe({
|
238
238
|
disabled,
|
239
239
|
callback,
|
240
240
|
subject: control._subjects.state,
|
241
241
|
});
|
242
|
-
React.useEffect(() =>
|
243
|
-
_mounted.current =
|
242
|
+
React.useEffect(() => {
|
243
|
+
_mounted.current = true;
|
244
|
+
return () => {
|
245
|
+
_mounted.current = false;
|
246
|
+
};
|
244
247
|
}, []);
|
245
248
|
return getProxyFormState(formState, control._proxyFormState, _localProxyFormState.current, false);
|
246
249
|
}
|
@@ -298,11 +301,12 @@ function useWatch(props) {
|
|
298
301
|
const fieldValues = generateWatchOutput(_name.current, control._names, formState.values || control._formValues);
|
299
302
|
updateValue(isUndefined(_name.current) ||
|
300
303
|
(isObject(fieldValues) && !objectHasFunction(fieldValues))
|
301
|
-
?
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
304
|
+
? { ...fieldValues }
|
305
|
+
: Array.isArray(fieldValues)
|
306
|
+
? [...fieldValues]
|
307
|
+
: isUndefined(fieldValues)
|
308
|
+
? defaultValue
|
309
|
+
: fieldValues);
|
306
310
|
}
|
307
311
|
}, [control, exact, defaultValue]);
|
308
312
|
useSubscribe({
|
@@ -357,7 +361,10 @@ function useController(props) {
|
|
357
361
|
control,
|
358
362
|
name,
|
359
363
|
});
|
360
|
-
const _registerProps = React.useRef(control.register(name,
|
364
|
+
const _registerProps = React.useRef(control.register(name, {
|
365
|
+
...props.rules,
|
366
|
+
value,
|
367
|
+
}));
|
361
368
|
React.useEffect(() => {
|
362
369
|
const updateMounted = (name, value) => {
|
363
370
|
const field = get(control._fields, name);
|
@@ -458,7 +465,14 @@ function useController(props) {
|
|
458
465
|
const Controller = (props) => props.render(useController(props));
|
459
466
|
|
460
467
|
var appendErrors = (name, validateAllFieldCriteria, errors, type, message) => validateAllFieldCriteria
|
461
|
-
?
|
468
|
+
? {
|
469
|
+
...errors[name],
|
470
|
+
types: {
|
471
|
+
...(errors[name] && errors[name].types ? errors[name].types : {}),
|
472
|
+
[type]: message || true,
|
473
|
+
},
|
474
|
+
}
|
475
|
+
: {};
|
462
476
|
|
463
477
|
var isKey = (value) => /^\w*$/.test(value);
|
464
478
|
|
@@ -491,8 +505,7 @@ const focusFieldBy = (fields, callback, fieldsNames) => {
|
|
491
505
|
for (const key of fieldsNames || Object.keys(fields)) {
|
492
506
|
const field = get(fields, key);
|
493
507
|
if (field) {
|
494
|
-
const _f = field
|
495
|
-
const current = omit(field, '_f');
|
508
|
+
const { _f, ...currentField } = field;
|
496
509
|
if (_f && callback(_f.name)) {
|
497
510
|
if (_f.ref.focus && isUndefined(_f.ref.focus())) {
|
498
511
|
break;
|
@@ -502,8 +515,8 @@ const focusFieldBy = (fields, callback, fieldsNames) => {
|
|
502
515
|
break;
|
503
516
|
}
|
504
517
|
}
|
505
|
-
else if (isObject(
|
506
|
-
focusFieldBy(
|
518
|
+
else if (isObject(currentField)) {
|
519
|
+
focusFieldBy(currentField, callback);
|
507
520
|
}
|
508
521
|
}
|
509
522
|
}
|
@@ -789,7 +802,10 @@ function useFieldArray(props) {
|
|
789
802
|
insert: React.useCallback(insert$1, [updateValues, name, control]),
|
790
803
|
update: React.useCallback(update, [updateValues, name, control]),
|
791
804
|
replace: React.useCallback(replace, [updateValues, name, control]),
|
792
|
-
fields: React.useMemo(() => fields.map((field, index) => (
|
805
|
+
fields: React.useMemo(() => fields.map((field, index) => ({
|
806
|
+
...field,
|
807
|
+
[keyName]: ids.current[index] || generateId(),
|
808
|
+
})), [fields, keyName]),
|
793
809
|
};
|
794
810
|
}
|
795
811
|
|
@@ -945,7 +961,7 @@ function getDirtyFieldsFromDefaultValues(data, formValues, dirtyFieldsFromValues
|
|
945
961
|
isPrimitive(dirtyFieldsFromValues[key])) {
|
946
962
|
dirtyFieldsFromValues[key] = Array.isArray(data[key])
|
947
963
|
? markFieldsDirty(data[key], [])
|
948
|
-
:
|
964
|
+
: { ...markFieldsDirty(data[key]) };
|
949
965
|
}
|
950
966
|
else {
|
951
967
|
getDirtyFieldsFromDefaultValues(data[key], isNullOrUndefined(formValues) ? {} : formValues[key], dirtyFieldsFromValues[key]);
|
@@ -1155,8 +1171,12 @@ var validateField = async (field, inputValue, validateAllFieldCriteria, shouldUs
|
|
1155
1171
|
const appendErrorsCurry = appendErrors.bind(null, name, validateAllFieldCriteria, error);
|
1156
1172
|
const getMinMaxMessage = (exceedMax, maxLengthMessage, minLengthMessage, maxType = INPUT_VALIDATION_RULES.maxLength, minType = INPUT_VALIDATION_RULES.minLength) => {
|
1157
1173
|
const message = exceedMax ? maxLengthMessage : minLengthMessage;
|
1158
|
-
error[name] =
|
1159
|
-
|
1174
|
+
error[name] = {
|
1175
|
+
type: exceedMax ? maxType : minType,
|
1176
|
+
message,
|
1177
|
+
ref,
|
1178
|
+
...appendErrorsCurry(exceedMax ? maxType : minType, message),
|
1179
|
+
};
|
1160
1180
|
};
|
1161
1181
|
if (required &&
|
1162
1182
|
((!isRadioOrCheckbox && (isEmpty || isNullOrUndefined(inputValue))) ||
|
@@ -1167,7 +1187,12 @@ var validateField = async (field, inputValue, validateAllFieldCriteria, shouldUs
|
|
1167
1187
|
? { value: !!required, message: required }
|
1168
1188
|
: getValueAndMessage(required);
|
1169
1189
|
if (value) {
|
1170
|
-
error[name] =
|
1190
|
+
error[name] = {
|
1191
|
+
type: INPUT_VALIDATION_RULES.required,
|
1192
|
+
message,
|
1193
|
+
ref: inputRef,
|
1194
|
+
...appendErrorsCurry(INPUT_VALIDATION_RULES.required, message),
|
1195
|
+
};
|
1171
1196
|
if (!validateAllFieldCriteria) {
|
1172
1197
|
setCustomValidity(message);
|
1173
1198
|
return error;
|
@@ -1223,8 +1248,12 @@ var validateField = async (field, inputValue, validateAllFieldCriteria, shouldUs
|
|
1223
1248
|
if (pattern && !isEmpty && isString(inputValue)) {
|
1224
1249
|
const { value: patternValue, message } = getValueAndMessage(pattern);
|
1225
1250
|
if (isRegex(patternValue) && !inputValue.match(patternValue)) {
|
1226
|
-
error[name] =
|
1227
|
-
|
1251
|
+
error[name] = {
|
1252
|
+
type: INPUT_VALIDATION_RULES.pattern,
|
1253
|
+
message,
|
1254
|
+
ref,
|
1255
|
+
...appendErrorsCurry(INPUT_VALIDATION_RULES.pattern, message),
|
1256
|
+
};
|
1228
1257
|
if (!validateAllFieldCriteria) {
|
1229
1258
|
setCustomValidity(message);
|
1230
1259
|
return error;
|
@@ -1236,7 +1265,10 @@ var validateField = async (field, inputValue, validateAllFieldCriteria, shouldUs
|
|
1236
1265
|
const result = await validate(inputValue);
|
1237
1266
|
const validateError = getValidateError(result, inputRef);
|
1238
1267
|
if (validateError) {
|
1239
|
-
error[name] =
|
1268
|
+
error[name] = {
|
1269
|
+
...validateError,
|
1270
|
+
...appendErrorsCurry(INPUT_VALIDATION_RULES.validate, validateError.message),
|
1271
|
+
};
|
1240
1272
|
if (!validateAllFieldCriteria) {
|
1241
1273
|
setCustomValidity(validateError.message);
|
1242
1274
|
return error;
|
@@ -1251,7 +1283,10 @@ var validateField = async (field, inputValue, validateAllFieldCriteria, shouldUs
|
|
1251
1283
|
}
|
1252
1284
|
const validateError = getValidateError(await validate[key](inputValue), inputRef, key);
|
1253
1285
|
if (validateError) {
|
1254
|
-
validationResult =
|
1286
|
+
validationResult = {
|
1287
|
+
...validateError,
|
1288
|
+
...appendErrorsCurry(key, validateError.message),
|
1289
|
+
};
|
1255
1290
|
setCustomValidity(validateError.message);
|
1256
1291
|
if (validateAllFieldCriteria) {
|
1257
1292
|
error[name] = validationResult;
|
@@ -1259,7 +1294,10 @@ var validateField = async (field, inputValue, validateAllFieldCriteria, shouldUs
|
|
1259
1294
|
}
|
1260
1295
|
}
|
1261
1296
|
if (!isEmptyObject(validationResult)) {
|
1262
|
-
error[name] =
|
1297
|
+
error[name] = {
|
1298
|
+
ref: inputRef,
|
1299
|
+
...validationResult,
|
1300
|
+
};
|
1263
1301
|
if (!validateAllFieldCriteria) {
|
1264
1302
|
return error;
|
1265
1303
|
}
|
@@ -1276,7 +1314,10 @@ const defaultOptions = {
|
|
1276
1314
|
shouldFocusError: true,
|
1277
1315
|
};
|
1278
1316
|
function createFormControl(props = {}) {
|
1279
|
-
let _options =
|
1317
|
+
let _options = {
|
1318
|
+
...defaultOptions,
|
1319
|
+
...props,
|
1320
|
+
};
|
1280
1321
|
let _formState = {
|
1281
1322
|
isDirty: false,
|
1282
1323
|
isValidating: false,
|
@@ -1290,7 +1331,7 @@ function createFormControl(props = {}) {
|
|
1290
1331
|
errors: {},
|
1291
1332
|
};
|
1292
1333
|
let _fields = {};
|
1293
|
-
let _defaultValues = _options.defaultValues || {};
|
1334
|
+
let _defaultValues = cloneObject(_options.defaultValues) || {};
|
1294
1335
|
let _formValues = _options.shouldUnregister
|
1295
1336
|
? {}
|
1296
1337
|
: cloneObject(_defaultValues);
|
@@ -1444,8 +1485,16 @@ function createFormControl(props = {}) {
|
|
1444
1485
|
!isEmptyObject(fieldState) ||
|
1445
1486
|
shouldUpdateValid) &&
|
1446
1487
|
!shouldSkipRender) {
|
1447
|
-
const updatedFormState =
|
1448
|
-
|
1488
|
+
const updatedFormState = {
|
1489
|
+
...fieldState,
|
1490
|
+
...(shouldUpdateValid ? { isValid } : {}),
|
1491
|
+
errors: _formState.errors,
|
1492
|
+
name,
|
1493
|
+
};
|
1494
|
+
_formState = {
|
1495
|
+
..._formState,
|
1496
|
+
...updatedFormState,
|
1497
|
+
};
|
1449
1498
|
_subjects.state.next(updatedFormState);
|
1450
1499
|
}
|
1451
1500
|
validateFields[name]--;
|
@@ -1458,7 +1507,7 @@ function createFormControl(props = {}) {
|
|
1458
1507
|
}
|
1459
1508
|
};
|
1460
1509
|
const _executeSchema = async (name) => _options.resolver
|
1461
|
-
? await _options.resolver(
|
1510
|
+
? await _options.resolver({ ..._formValues }, _options.context, getResolverOptions(name || _names.mount, _fields, _options.criteriaMode, _options.shouldUseNativeValidation))
|
1462
1511
|
: {};
|
1463
1512
|
const executeSchemaAndUpdateState = async (names) => {
|
1464
1513
|
const { errors } = await _executeSchema();
|
@@ -1481,8 +1530,7 @@ function createFormControl(props = {}) {
|
|
1481
1530
|
for (const name in fields) {
|
1482
1531
|
const field = fields[name];
|
1483
1532
|
if (field) {
|
1484
|
-
const fieldReference = field
|
1485
|
-
const fieldValue = omit(field, '_f');
|
1533
|
+
const { _f: fieldReference, ...fieldValue } = field;
|
1486
1534
|
if (fieldReference) {
|
1487
1535
|
const fieldError = await validateField(field, get(_formValues, fieldReference.name), shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation);
|
1488
1536
|
if (fieldError[fieldReference.name]) {
|
@@ -1517,13 +1565,15 @@ function createFormControl(props = {}) {
|
|
1517
1565
|
const _getDirty = (name, data) => (name && data && set(_formValues, name, data),
|
1518
1566
|
!deepEqual(getValues(), _defaultValues));
|
1519
1567
|
const _getWatch = (names, defaultValue, isGlobal) => {
|
1520
|
-
const fieldValues =
|
1521
|
-
|
1522
|
-
|
1523
|
-
|
1524
|
-
|
1525
|
-
|
1526
|
-
|
1568
|
+
const fieldValues = {
|
1569
|
+
...(_stateFlags.mount
|
1570
|
+
? _formValues
|
1571
|
+
: isUndefined(defaultValue)
|
1572
|
+
? _defaultValues
|
1573
|
+
: isString(names)
|
1574
|
+
? { [names]: defaultValue }
|
1575
|
+
: defaultValue),
|
1576
|
+
};
|
1527
1577
|
return generateWatchOutput(names, _names, fieldValues, isGlobal);
|
1528
1578
|
};
|
1529
1579
|
const _getFieldArray = (name) => compact(get(_stateFlags.mount ? _formValues : _defaultValues, name, props.shouldUnregister ? get(_defaultValues, name, []) : []));
|
@@ -1649,7 +1699,7 @@ function createFormControl(props = {}) {
|
|
1649
1699
|
});
|
1650
1700
|
if (shouldSkipValidation) {
|
1651
1701
|
return (shouldRender &&
|
1652
|
-
_subjects.state.next(
|
1702
|
+
_subjects.state.next({ name, ...(watched ? {} : fieldState) }));
|
1653
1703
|
}
|
1654
1704
|
!isBlurEvent && watched && _subjects.state.next({});
|
1655
1705
|
validateFields[name] = validateFields[name] ? +1 : 1;
|
@@ -1697,17 +1747,25 @@ function createFormControl(props = {}) {
|
|
1697
1747
|
else {
|
1698
1748
|
validationResult = isValid = await executeBuildInValidation(_fields);
|
1699
1749
|
}
|
1700
|
-
_subjects.state.next(
|
1701
|
-
(
|
1702
|
-
|
1703
|
-
|
1750
|
+
_subjects.state.next({
|
1751
|
+
...(!isString(name) ||
|
1752
|
+
(_proxyFormState.isValid && isValid !== _formState.isValid)
|
1753
|
+
? {}
|
1754
|
+
: { name }),
|
1755
|
+
...(_options.resolver ? { isValid } : {}),
|
1756
|
+
errors: _formState.errors,
|
1757
|
+
isValidating: false,
|
1758
|
+
});
|
1704
1759
|
options.shouldFocus &&
|
1705
1760
|
!validationResult &&
|
1706
1761
|
focusFieldBy(_fields, (key) => get(_formState.errors, key), name ? fieldNames : _names.mount);
|
1707
1762
|
return validationResult;
|
1708
1763
|
};
|
1709
1764
|
const getValues = (fieldNames) => {
|
1710
|
-
const values =
|
1765
|
+
const values = {
|
1766
|
+
..._defaultValues,
|
1767
|
+
...(_stateFlags.mount ? _formValues : {}),
|
1768
|
+
};
|
1711
1769
|
return isUndefined(fieldNames)
|
1712
1770
|
? values
|
1713
1771
|
: isString(fieldNames)
|
@@ -1730,7 +1788,10 @@ function createFormControl(props = {}) {
|
|
1730
1788
|
};
|
1731
1789
|
const setError = (name, error, options) => {
|
1732
1790
|
const ref = (get(_fields, name, { _f: {} })._f || {}).ref;
|
1733
|
-
set(_formState.errors, name,
|
1791
|
+
set(_formState.errors, name, {
|
1792
|
+
...error,
|
1793
|
+
ref,
|
1794
|
+
});
|
1734
1795
|
_subjects.state.next({
|
1735
1796
|
name,
|
1736
1797
|
errors: _formState.errors,
|
@@ -1761,14 +1822,22 @@ function createFormControl(props = {}) {
|
|
1761
1822
|
}
|
1762
1823
|
}
|
1763
1824
|
_subjects.watch.next({});
|
1764
|
-
_subjects.state.next(
|
1825
|
+
_subjects.state.next({
|
1826
|
+
..._formState,
|
1827
|
+
...(!options.keepDirty ? {} : { isDirty: _getDirty() }),
|
1828
|
+
});
|
1765
1829
|
!options.keepIsValid && _updateValid();
|
1766
1830
|
};
|
1767
1831
|
const register = (name, options = {}) => {
|
1768
1832
|
let field = get(_fields, name);
|
1769
1833
|
const disabledIsDefined = isBoolean(options.disabled);
|
1770
1834
|
set(_fields, name, {
|
1771
|
-
_f:
|
1835
|
+
_f: {
|
1836
|
+
...(field && field._f ? field._f : { ref: { name } }),
|
1837
|
+
name,
|
1838
|
+
mount: true,
|
1839
|
+
...options,
|
1840
|
+
},
|
1772
1841
|
});
|
1773
1842
|
_names.mount.add(name);
|
1774
1843
|
field
|
@@ -1777,17 +1846,22 @@ function createFormControl(props = {}) {
|
|
1777
1846
|
? undefined
|
1778
1847
|
: get(_formValues, name, getFieldValue(field._f)))
|
1779
1848
|
: updateValidAndValue(name, true, options.value);
|
1780
|
-
return
|
1781
|
-
? {
|
1782
|
-
|
1783
|
-
|
1784
|
-
|
1785
|
-
|
1786
|
-
|
1787
|
-
|
1788
|
-
|
1789
|
-
|
1790
|
-
|
1849
|
+
return {
|
1850
|
+
...(disabledIsDefined ? { disabled: options.disabled } : {}),
|
1851
|
+
...(_options.shouldUseNativeValidation
|
1852
|
+
? {
|
1853
|
+
required: !!options.required,
|
1854
|
+
min: getRuleValue(options.min),
|
1855
|
+
max: getRuleValue(options.max),
|
1856
|
+
minLength: getRuleValue(options.minLength),
|
1857
|
+
maxLength: getRuleValue(options.maxLength),
|
1858
|
+
pattern: getRuleValue(options.pattern),
|
1859
|
+
}
|
1860
|
+
: {}),
|
1861
|
+
name,
|
1862
|
+
onChange,
|
1863
|
+
onBlur: onChange,
|
1864
|
+
ref: (ref) => {
|
1791
1865
|
if (ref) {
|
1792
1866
|
register(name, options);
|
1793
1867
|
field = get(_fields, name);
|
@@ -1804,12 +1878,15 @@ function createFormControl(props = {}) {
|
|
1804
1878
|
return;
|
1805
1879
|
}
|
1806
1880
|
set(_fields, name, {
|
1807
|
-
_f:
|
1808
|
-
|
1809
|
-
|
1810
|
-
|
1811
|
-
|
1812
|
-
|
1881
|
+
_f: {
|
1882
|
+
...field._f,
|
1883
|
+
...(radioOrCheckbox
|
1884
|
+
? {
|
1885
|
+
refs: [...refs.filter(live), fieldRef],
|
1886
|
+
ref: { type: fieldRef.type, name },
|
1887
|
+
}
|
1888
|
+
: { ref: fieldRef }),
|
1889
|
+
},
|
1813
1890
|
});
|
1814
1891
|
updateValidAndValue(name, false, undefined, fieldRef);
|
1815
1892
|
}
|
@@ -1822,7 +1899,8 @@ function createFormControl(props = {}) {
|
|
1822
1899
|
!(isNameInFieldArray(_names.array, name) && _stateFlags.action) &&
|
1823
1900
|
_names.unMount.add(name);
|
1824
1901
|
}
|
1825
|
-
}
|
1902
|
+
},
|
1903
|
+
};
|
1826
1904
|
};
|
1827
1905
|
const handleSubmit = (onValid, onInvalid) => async (e) => {
|
1828
1906
|
if (e) {
|
@@ -1853,7 +1931,7 @@ function createFormControl(props = {}) {
|
|
1853
1931
|
}
|
1854
1932
|
else {
|
1855
1933
|
if (onInvalid) {
|
1856
|
-
await onInvalid(
|
1934
|
+
await onInvalid({ ..._formState.errors }, e);
|
1857
1935
|
}
|
1858
1936
|
_options.shouldFocusError &&
|
1859
1937
|
focusFieldBy(_fields, (key) => get(_formState.errors, key), _names.mount);
|
@@ -1896,7 +1974,7 @@ function createFormControl(props = {}) {
|
|
1896
1974
|
unset(_formState.errors, name);
|
1897
1975
|
_proxyFormState.isValid && _updateValid();
|
1898
1976
|
}
|
1899
|
-
_subjects.state.next(
|
1977
|
+
_subjects.state.next({ ..._formState });
|
1900
1978
|
}
|
1901
1979
|
};
|
1902
1980
|
const reset = (formValues, keepStateOptions = {}) => {
|
@@ -1964,7 +2042,10 @@ function createFormControl(props = {}) {
|
|
1964
2042
|
dirtyFields: keepStateOptions.keepDirty
|
1965
2043
|
? _formState.dirtyFields
|
1966
2044
|
: (keepStateOptions.keepDefaultValues && formValues
|
1967
|
-
? Object.entries(formValues).reduce((previous, [key, value]) => (
|
2045
|
+
? Object.entries(formValues).reduce((previous, [key, value]) => ({
|
2046
|
+
...previous,
|
2047
|
+
[key]: value !== get(_defaultValues, key),
|
2048
|
+
}), {})
|
1968
2049
|
: {}),
|
1969
2050
|
touchedFields: keepStateOptions.keepTouched
|
1970
2051
|
? _formState.touchedFields
|
@@ -2026,7 +2107,10 @@ function createFormControl(props = {}) {
|
|
2026
2107
|
return _options;
|
2027
2108
|
},
|
2028
2109
|
set _options(value) {
|
2029
|
-
_options =
|
2110
|
+
_options = {
|
2111
|
+
..._options,
|
2112
|
+
...value,
|
2113
|
+
};
|
2030
2114
|
},
|
2031
2115
|
},
|
2032
2116
|
trigger,
|
@@ -2092,13 +2176,19 @@ function useForm(props = {}) {
|
|
2092
2176
|
_formControl.current.control._options = props;
|
2093
2177
|
}
|
2094
2178
|
else {
|
2095
|
-
_formControl.current =
|
2179
|
+
_formControl.current = {
|
2180
|
+
...createFormControl(props),
|
2181
|
+
formState,
|
2182
|
+
};
|
2096
2183
|
}
|
2097
2184
|
const control = _formControl.current.control;
|
2098
2185
|
const callback = React.useCallback((value) => {
|
2099
2186
|
if (shouldRenderFormState(value, control._proxyFormState, true)) {
|
2100
|
-
control._formState =
|
2101
|
-
|
2187
|
+
control._formState = {
|
2188
|
+
...control._formState,
|
2189
|
+
...value,
|
2190
|
+
};
|
2191
|
+
updateFormState({ ...control._formState });
|
2102
2192
|
}
|
2103
2193
|
}, [control]);
|
2104
2194
|
useSubscribe({
|