react-hook-form 7.80.0 → 7.81.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/dist/fieldArray.d.ts +36 -0
- package/dist/fieldArray.d.ts.map +1 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.mjs +44 -14
- 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/react-server.esm.mjs +35 -3
- package/dist/react-server.esm.mjs.map +1 -1
- package/dist/types/fieldArray.d.ts +21 -0
- package/dist/types/fieldArray.d.ts.map +1 -1
- package/dist/useFieldArray.d.ts.map +1 -1
- package/dist/utils/flatten.d.ts.map +1 -1
- package/dist/utils/unset.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/index.esm.mjs
CHANGED
|
@@ -605,7 +605,9 @@ const Controller = (props) => props.render(useController(props));
|
|
|
605
605
|
const flatten = (obj) => {
|
|
606
606
|
const output = {};
|
|
607
607
|
for (const key of Object.keys(obj)) {
|
|
608
|
-
if (isObjectType(obj[key]) &&
|
|
608
|
+
if (isObjectType(obj[key]) &&
|
|
609
|
+
obj[key] !== null &&
|
|
610
|
+
!isDateObject(obj[key])) {
|
|
609
611
|
const nested = flatten(obj[key]);
|
|
610
612
|
for (const nestedKey of Object.keys(nested)) {
|
|
611
613
|
output[`${key}.${nestedKey}`] = nested[nestedKey];
|
|
@@ -950,6 +952,9 @@ function unset(object, path) {
|
|
|
950
952
|
: isKey(path)
|
|
951
953
|
? [path]
|
|
952
954
|
: stringToPath(path);
|
|
955
|
+
if (paths.some((segment) => PROTOTYPE_KEYWORDS.includes(String(segment)))) {
|
|
956
|
+
return object;
|
|
957
|
+
}
|
|
953
958
|
const childObject = paths.length === 1 ? object : baseGet(object, paths);
|
|
954
959
|
const index = paths.length - 1;
|
|
955
960
|
const key = paths[index];
|
|
@@ -1254,7 +1259,7 @@ var shouldSubscribeByName = (name, signalName, exact) => !name ||
|
|
|
1254
1259
|
name === signalName ||
|
|
1255
1260
|
convertToArrayPayload(name).some((currentName) => currentName &&
|
|
1256
1261
|
(exact
|
|
1257
|
-
? currentName === signalName
|
|
1262
|
+
? currentName === signalName || currentName.startsWith(signalName + '.')
|
|
1258
1263
|
: currentName.startsWith(signalName) ||
|
|
1259
1264
|
signalName.startsWith(currentName)));
|
|
1260
1265
|
|
|
@@ -2065,8 +2070,11 @@ function createFormControl(props = {}) {
|
|
|
2065
2070
|
..._formValues,
|
|
2066
2071
|
...updatedFormValues,
|
|
2067
2072
|
};
|
|
2073
|
+
const flattenedUpdates = flatten(updatedFormValues);
|
|
2068
2074
|
for (const fieldName of _names.mount) {
|
|
2069
|
-
|
|
2075
|
+
if (fieldName in flattenedUpdates) {
|
|
2076
|
+
_setValue(fieldName, flattenedUpdates[fieldName], options, true, true);
|
|
2077
|
+
}
|
|
2070
2078
|
}
|
|
2071
2079
|
_subjects.state.next({
|
|
2072
2080
|
..._formState,
|
|
@@ -2658,6 +2666,8 @@ function createFormControl(props = {}) {
|
|
|
2658
2666
|
values: { ...values },
|
|
2659
2667
|
});
|
|
2660
2668
|
_subjects.state.next({
|
|
2669
|
+
name: undefined,
|
|
2670
|
+
type: undefined,
|
|
2661
2671
|
values: { ...values },
|
|
2662
2672
|
});
|
|
2663
2673
|
}
|
|
@@ -2740,9 +2750,15 @@ function createFormControl(props = {}) {
|
|
|
2740
2750
|
}
|
|
2741
2751
|
};
|
|
2742
2752
|
const _setFormState = (updatedFormState) => {
|
|
2753
|
+
// `name`, `type`, and `values` describe the event that produced this
|
|
2754
|
+
// update, not the form's persisted state (they aren't part of
|
|
2755
|
+
// `FormState`). Merging them in would leak a stale `name`/`type` from
|
|
2756
|
+
// one event into a later, unrelated notification that doesn't specify
|
|
2757
|
+
// its own.
|
|
2758
|
+
const { name, type, values, ...formState } = updatedFormState;
|
|
2743
2759
|
_formState = {
|
|
2744
2760
|
..._formState,
|
|
2745
|
-
...
|
|
2761
|
+
...formState,
|
|
2746
2762
|
};
|
|
2747
2763
|
};
|
|
2748
2764
|
const _resetDefaultValues = () => isFunction(_options.defaultValues) &&
|
|
@@ -3118,18 +3134,28 @@ function useFieldArray(props) {
|
|
|
3118
3134
|
!validationModes.isOnBlur) {
|
|
3119
3135
|
if (control._options.resolver) {
|
|
3120
3136
|
control._runSchema([name]).then((result) => {
|
|
3137
|
+
var _a, _b;
|
|
3121
3138
|
control._updateIsValidating([name]);
|
|
3122
3139
|
const error = get(result.errors, name);
|
|
3123
3140
|
const existingError = get(control._formState.errors, name);
|
|
3141
|
+
const existingErrorType = existingError && (existingError.type || ((_a = existingError.root) === null || _a === void 0 ? void 0 : _a.type));
|
|
3142
|
+
const existingErrorMessage = existingError &&
|
|
3143
|
+
(existingError.message || ((_b = existingError.root) === null || _b === void 0 ? void 0 : _b.message));
|
|
3124
3144
|
if (existingError
|
|
3125
|
-
? (!error &&
|
|
3145
|
+
? (!error && existingErrorType) ||
|
|
3126
3146
|
(error &&
|
|
3127
|
-
(
|
|
3128
|
-
|
|
3147
|
+
(existingErrorType !== error.type ||
|
|
3148
|
+
existingErrorMessage !== error.message))
|
|
3129
3149
|
: error && error.type) {
|
|
3130
|
-
error
|
|
3131
|
-
|
|
3132
|
-
|
|
3150
|
+
if (error) {
|
|
3151
|
+
isObject(error) &&
|
|
3152
|
+
!Object.keys(error).some((key) => !Number.isNaN(+key))
|
|
3153
|
+
? updateFieldArrayRootError(control._formState.errors, { [name]: error }, name)
|
|
3154
|
+
: set(control._formState.errors, name, error);
|
|
3155
|
+
}
|
|
3156
|
+
else {
|
|
3157
|
+
unset(control._formState.errors, name);
|
|
3158
|
+
}
|
|
3133
3159
|
control._subjects.state.next({
|
|
3134
3160
|
errors: control._formState.errors,
|
|
3135
3161
|
});
|
|
@@ -3149,10 +3175,14 @@ function useFieldArray(props) {
|
|
|
3149
3175
|
}
|
|
3150
3176
|
}
|
|
3151
3177
|
}
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3178
|
+
// External updates that change `fields` (e.g. reset() or setValue() on
|
|
3179
|
+
// the array) already notify subscribers with the up-to-date values
|
|
3180
|
+
// themselves, so only re-broadcast here for genuine array method calls.
|
|
3181
|
+
_actioned.current &&
|
|
3182
|
+
control._subjects.state.next({
|
|
3183
|
+
name,
|
|
3184
|
+
values: cloneObject(control._formValues),
|
|
3185
|
+
});
|
|
3156
3186
|
control._names.focus &&
|
|
3157
3187
|
iterateFieldsByAction(control._fields, (ref, key) => {
|
|
3158
3188
|
if (control._names.focus &&
|