react-hook-form 7.75.0 → 7.76.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 +13 -9
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.mjs +70 -17
- 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/{isNameInFieldArray.d.ts → getFieldArrayParentNames.d.ts} +2 -2
- package/dist/logic/getFieldArrayParentNames.d.ts.map +1 -0
- package/dist/react-server.esm.mjs +64 -15
- package/dist/react-server.esm.mjs.map +1 -1
- package/dist/types/form.d.ts +2 -2
- package/dist/types/utils.d.ts +2 -2
- package/dist/useController.d.ts.map +1 -1
- package/dist/useForm.d.ts.map +1 -1
- package/dist/watch.d.ts +1 -1
- package/dist/watch.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/logic/isNameInFieldArray.d.ts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createFormControl.d.ts","sourceRoot":"","sources":["../../src/logic/createFormControl.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAaV,WAAW,EAiBX,YAAY,EAIZ,aAAa,EAYd,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"createFormControl.d.ts","sourceRoot":"","sources":["../../src/logic/createFormControl.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAaV,WAAW,EAiBX,YAAY,EAIZ,aAAa,EAYd,MAAM,UAAU,CAAC;AAuDlB,eAAO,MAAM,kBAAkB;;;;;;;;;;;;CAY9B,CAAC;AAEF,wBAAgB,iBAAiB,CAC/B,YAAY,SAAS,WAAW,GAAG,WAAW,EAC9C,QAAQ,GAAG,GAAG,EACd,kBAAkB,GAAG,YAAY,EAEjC,KAAK,GAAE,YAAY,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,CAAM,GACnE,IAAI,CACL,aAAa,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,CAAC,EACzD,WAAW,CACZ,GAAG;IACF,WAAW,EAAE,IAAI,CACf,aAAa,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,CAAC,EACzD,WAAW,CACZ,CAAC;CACH,CAssDA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { InternalFieldName } from '../types';
|
|
2
|
-
declare const _default: (names: Set<InternalFieldName>, name: InternalFieldName) =>
|
|
2
|
+
declare const _default: (names: Set<InternalFieldName>, name: InternalFieldName) => string[];
|
|
3
3
|
export default _default;
|
|
4
|
-
//# sourceMappingURL=
|
|
4
|
+
//# sourceMappingURL=getFieldArrayParentNames.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getFieldArrayParentNames.d.ts","sourceRoot":"","sources":["../../src/logic/getFieldArrayParentNames.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;yBAElC,OAAO,GAAG,CAAC,iBAAiB,CAAC,EAAE,MAAM,iBAAiB;AAAtE,wBAUE"}
|
|
@@ -376,6 +376,16 @@ var getEventValue = (event) => isObject(event) && event.target
|
|
|
376
376
|
: event.target.value
|
|
377
377
|
: event;
|
|
378
378
|
|
|
379
|
+
var getFieldArrayParentNames = (names, name) => {
|
|
380
|
+
const parts = name.split('.');
|
|
381
|
+
const matches = [];
|
|
382
|
+
let prefix = parts[0];
|
|
383
|
+
for (let i = 1; i < parts.length; prefix += '.' + parts[i++]) {
|
|
384
|
+
!isNaN(+parts[i]) && names.has(prefix) && matches.push(prefix);
|
|
385
|
+
}
|
|
386
|
+
return matches;
|
|
387
|
+
};
|
|
388
|
+
|
|
379
389
|
const defaultResult = {
|
|
380
390
|
value: false,
|
|
381
391
|
isValid: false,
|
|
@@ -496,10 +506,6 @@ var hasValidation = (options) => options.mount &&
|
|
|
496
506
|
options.pattern ||
|
|
497
507
|
options.validate);
|
|
498
508
|
|
|
499
|
-
var isNameInFieldArray = (names, name) => name
|
|
500
|
-
.split('.')
|
|
501
|
-
.some((part, index, arr) => !isNaN(Number(part)) && names.has(arr.slice(0, index).join('.')));
|
|
502
|
-
|
|
503
509
|
var isWatched = (name, _names, isBlurEvent) => !isBlurEvent &&
|
|
504
510
|
(_names.watchAll ||
|
|
505
511
|
_names.watch.has(name) ||
|
|
@@ -985,9 +991,28 @@ function createFormControl(props = {}) {
|
|
|
985
991
|
isValid: false,
|
|
986
992
|
});
|
|
987
993
|
};
|
|
994
|
+
const hasExplicitNullIntermediate = (name) => {
|
|
995
|
+
const segments = isKey(name) ? [name] : stringToPath(name);
|
|
996
|
+
let formValues = _formValues;
|
|
997
|
+
let defaultValues = _defaultValues;
|
|
998
|
+
for (let i = 0; i < segments.length - 1; i++) {
|
|
999
|
+
const key = segments[i];
|
|
1000
|
+
formValues = isNullOrUndefined(formValues) ? formValues : formValues[key];
|
|
1001
|
+
defaultValues = isNullOrUndefined(defaultValues)
|
|
1002
|
+
? defaultValues
|
|
1003
|
+
: defaultValues[key];
|
|
1004
|
+
if (formValues === null && defaultValues !== null) {
|
|
1005
|
+
return true;
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
return false;
|
|
1009
|
+
};
|
|
988
1010
|
const updateValidAndValue = (name, shouldSkipSetValueAs, value, ref) => {
|
|
989
1011
|
const field = get(_fields, name);
|
|
990
1012
|
if (field) {
|
|
1013
|
+
if (hasExplicitNullIntermediate(name)) {
|
|
1014
|
+
return;
|
|
1015
|
+
}
|
|
991
1016
|
const wasUnsetInFormValues = isUndefined(get(_formValues, name));
|
|
992
1017
|
const defaultValue = get(_formValues, name, isUndefined(value) ? get(_defaultValues, name) : value);
|
|
993
1018
|
isUndefined(defaultValue) ||
|
|
@@ -1030,9 +1055,14 @@ function createFormControl(props = {}) {
|
|
|
1030
1055
|
}
|
|
1031
1056
|
const isCurrentFieldPristine = deepEqual(get(_defaultValues, name), fieldValue);
|
|
1032
1057
|
isPreviousDirty = !!get(_formState.dirtyFields, name);
|
|
1033
|
-
isCurrentFieldPristine
|
|
1034
|
-
|
|
1035
|
-
|
|
1058
|
+
if (isCurrentFieldPristine !== _formState.isDirty) {
|
|
1059
|
+
_formState.dirtyFields = getDirtyFields(_defaultValues, _formValues);
|
|
1060
|
+
}
|
|
1061
|
+
else {
|
|
1062
|
+
isCurrentFieldPristine
|
|
1063
|
+
? unset(_formState.dirtyFields, name)
|
|
1064
|
+
: set(_formState.dirtyFields, name, true);
|
|
1065
|
+
}
|
|
1036
1066
|
output.dirtyFields = _formState.dirtyFields;
|
|
1037
1067
|
shouldUpdateField =
|
|
1038
1068
|
shouldUpdateField ||
|
|
@@ -1099,7 +1129,9 @@ function createFormControl(props = {}) {
|
|
|
1099
1129
|
for (const name of names) {
|
|
1100
1130
|
const error = get(errors, name);
|
|
1101
1131
|
error
|
|
1102
|
-
?
|
|
1132
|
+
? _names.array.has(name) && isObject(error)
|
|
1133
|
+
? updateFieldArrayRootError(_formState.errors, { [name]: error }, name)
|
|
1134
|
+
: set(_formState.errors, name, error)
|
|
1103
1135
|
: unset(_formState.errors, name);
|
|
1104
1136
|
}
|
|
1105
1137
|
}
|
|
@@ -1121,8 +1153,8 @@ function createFormControl(props = {}) {
|
|
|
1121
1153
|
const error = result[key];
|
|
1122
1154
|
if (error) {
|
|
1123
1155
|
setError(`${FORM_ERROR_TYPE}.${key}`, {
|
|
1124
|
-
message: isString(
|
|
1125
|
-
type: INPUT_VALIDATION_RULES.validate,
|
|
1156
|
+
message: isString(error.message) ? error.message : '',
|
|
1157
|
+
type: error.type || INPUT_VALIDATION_RULES.validate,
|
|
1126
1158
|
});
|
|
1127
1159
|
}
|
|
1128
1160
|
}
|
|
@@ -1164,11 +1196,15 @@ function createFormControl(props = {}) {
|
|
|
1164
1196
|
if (_f) {
|
|
1165
1197
|
const isFieldArrayRoot = _names.array.has(_f.name);
|
|
1166
1198
|
const isPromiseFunction = field._f && hasPromiseValidation(field._f);
|
|
1167
|
-
|
|
1199
|
+
const shouldTrackIsValidatingState = _proxyFormState.validatingFields ||
|
|
1200
|
+
_proxyFormState.isValidating ||
|
|
1201
|
+
_proxySubscribeFormState.validatingFields ||
|
|
1202
|
+
_proxySubscribeFormState.isValidating;
|
|
1203
|
+
if (isPromiseFunction && shouldTrackIsValidatingState) {
|
|
1168
1204
|
_updateIsValidating([_f.name], true);
|
|
1169
1205
|
}
|
|
1170
1206
|
const fieldError = await validateField(field, _names.disabled, _formValues, shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation && !onlyCheckValid, isFieldArrayRoot);
|
|
1171
|
-
if (isPromiseFunction &&
|
|
1207
|
+
if (isPromiseFunction && shouldTrackIsValidatingState) {
|
|
1172
1208
|
_updateIsValidating([_f.name]);
|
|
1173
1209
|
}
|
|
1174
1210
|
if (fieldError[_f.name]) {
|
|
@@ -1296,7 +1332,9 @@ function createFormControl(props = {}) {
|
|
|
1296
1332
|
const cloneValue = cloneObject(value);
|
|
1297
1333
|
const previousValue = get(_formValues, name);
|
|
1298
1334
|
const isValueUnchanged = deepEqual(previousValue, cloneValue);
|
|
1299
|
-
|
|
1335
|
+
if (!isValueUnchanged) {
|
|
1336
|
+
set(_formValues, name, cloneValue);
|
|
1337
|
+
}
|
|
1300
1338
|
if (isFieldArray) {
|
|
1301
1339
|
_subjects.array.next({
|
|
1302
1340
|
name,
|
|
@@ -1327,10 +1365,16 @@ function createFormControl(props = {}) {
|
|
|
1327
1365
|
}
|
|
1328
1366
|
if (!isValueUnchanged) {
|
|
1329
1367
|
const watched = isWatched(name, _names);
|
|
1368
|
+
const values = cloneObject(_formValues);
|
|
1369
|
+
if (!isFieldArray) {
|
|
1370
|
+
for (const arrayName of getFieldArrayParentNames(_names.array, name)) {
|
|
1371
|
+
_subjects.array.next({ name: arrayName, values });
|
|
1372
|
+
}
|
|
1373
|
+
}
|
|
1330
1374
|
_subjects.state.next({
|
|
1331
1375
|
...(watched && _formState),
|
|
1332
1376
|
name: _state.mount || watched ? name : undefined,
|
|
1333
|
-
values
|
|
1377
|
+
values,
|
|
1334
1378
|
});
|
|
1335
1379
|
}
|
|
1336
1380
|
};
|
|
@@ -1343,6 +1387,9 @@ function createFormControl(props = {}) {
|
|
|
1343
1387
|
..._formValues,
|
|
1344
1388
|
...updatedFormValues,
|
|
1345
1389
|
};
|
|
1390
|
+
for (const fieldName of _names.mount) {
|
|
1391
|
+
setValue(fieldName, get(updatedFormValues, fieldName));
|
|
1392
|
+
}
|
|
1346
1393
|
_subjects.state.next({ ..._formState, values: _formValues });
|
|
1347
1394
|
}
|
|
1348
1395
|
};
|
|
@@ -1713,13 +1760,15 @@ function createFormControl(props = {}) {
|
|
|
1713
1760
|
field._f.mount = false;
|
|
1714
1761
|
}
|
|
1715
1762
|
(_options.shouldUnregister || options.shouldUnregister) &&
|
|
1716
|
-
!(
|
|
1763
|
+
!(getFieldArrayParentNames(_names.array, name).length &&
|
|
1764
|
+
_state.action) &&
|
|
1717
1765
|
_names.unMount.add(name);
|
|
1718
1766
|
}
|
|
1719
1767
|
},
|
|
1720
1768
|
};
|
|
1721
1769
|
};
|
|
1722
1770
|
const _focusError = () => _options.shouldFocusError &&
|
|
1771
|
+
!_options.shouldUseNativeValidation &&
|
|
1723
1772
|
iterateFieldsByAction(_fields, _focusInput, _names.mount);
|
|
1724
1773
|
const _disableForm = (disabled) => {
|
|
1725
1774
|
if (isBoolean(disabled)) {
|