react-hook-form 7.51.4 → 7.52.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 +5 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.mjs +51 -37
- 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 +3 -0
- package/dist/react-server.esm.mjs.map +1 -1
- package/dist/tsdoc-metadata.json +1 -1
- package/dist/types/form.d.ts +1 -0
- package/dist/types/form.d.ts.map +1 -1
- package/dist/types/validator.d.ts +2 -2
- package/dist/types/validator.d.ts.map +1 -1
- package/dist/useController.d.ts.map +1 -1
- package/dist/utils/set.d.ts +1 -1
- package/dist/utils/set.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.esm.mjs
CHANGED
@@ -78,6 +78,36 @@ var get = (object, path, defaultValue) => {
|
|
78
78
|
|
79
79
|
var isBoolean = (value) => typeof value === 'boolean';
|
80
80
|
|
81
|
+
var isKey = (value) => /^\w*$/.test(value);
|
82
|
+
|
83
|
+
var stringToPath = (input) => compact(input.replace(/["|']|\]/g, '').split(/\.|\[/));
|
84
|
+
|
85
|
+
var set = (object, path, value) => {
|
86
|
+
let index = -1;
|
87
|
+
const tempPath = isKey(path) ? [path] : stringToPath(path);
|
88
|
+
const length = tempPath.length;
|
89
|
+
const lastIndex = length - 1;
|
90
|
+
while (++index < length) {
|
91
|
+
const key = tempPath[index];
|
92
|
+
let newValue = value;
|
93
|
+
if (index !== lastIndex) {
|
94
|
+
const objValue = object[key];
|
95
|
+
newValue =
|
96
|
+
isObject(objValue) || Array.isArray(objValue)
|
97
|
+
? objValue
|
98
|
+
: !isNaN(+tempPath[index + 1])
|
99
|
+
? []
|
100
|
+
: {};
|
101
|
+
}
|
102
|
+
if (key === '__proto__') {
|
103
|
+
return;
|
104
|
+
}
|
105
|
+
object[key] = newValue;
|
106
|
+
object = object[key];
|
107
|
+
}
|
108
|
+
return object;
|
109
|
+
};
|
110
|
+
|
81
111
|
const EVENTS = {
|
82
112
|
BLUR: 'blur',
|
83
113
|
FOCUS_OUT: 'focusout',
|
@@ -340,33 +370,6 @@ function useWatch(props) {
|
|
340
370
|
return value;
|
341
371
|
}
|
342
372
|
|
343
|
-
var isKey = (value) => /^\w*$/.test(value);
|
344
|
-
|
345
|
-
var stringToPath = (input) => compact(input.replace(/["|']|\]/g, '').split(/\.|\[/));
|
346
|
-
|
347
|
-
var set = (object, path, value) => {
|
348
|
-
let index = -1;
|
349
|
-
const tempPath = isKey(path) ? [path] : stringToPath(path);
|
350
|
-
const length = tempPath.length;
|
351
|
-
const lastIndex = length - 1;
|
352
|
-
while (++index < length) {
|
353
|
-
const key = tempPath[index];
|
354
|
-
let newValue = value;
|
355
|
-
if (index !== lastIndex) {
|
356
|
-
const objValue = object[key];
|
357
|
-
newValue =
|
358
|
-
isObject(objValue) || Array.isArray(objValue)
|
359
|
-
? objValue
|
360
|
-
: !isNaN(+tempPath[index + 1])
|
361
|
-
? []
|
362
|
-
: {};
|
363
|
-
}
|
364
|
-
object[key] = newValue;
|
365
|
-
object = object[key];
|
366
|
-
}
|
367
|
-
return object;
|
368
|
-
};
|
369
|
-
|
370
373
|
/**
|
371
374
|
* Custom hook to work with controlled component, this function provide you with both form and field level state. Re-render is isolated at the hook level.
|
372
375
|
*
|
@@ -414,7 +417,7 @@ function useController(props) {
|
|
414
417
|
const _shouldUnregisterField = control._options.shouldUnregister || shouldUnregister;
|
415
418
|
const updateMounted = (name, value) => {
|
416
419
|
const field = get(control._fields, name);
|
417
|
-
if (field) {
|
420
|
+
if (field && field._f) {
|
418
421
|
field._f.mount = value;
|
419
422
|
}
|
420
423
|
};
|
@@ -1676,7 +1679,9 @@ function createFormControl(props = {}) {
|
|
1676
1679
|
const output = {
|
1677
1680
|
name,
|
1678
1681
|
};
|
1679
|
-
const disabledField = !!(get(_fields, name) &&
|
1682
|
+
const disabledField = !!(get(_fields, name) &&
|
1683
|
+
get(_fields, name)._f &&
|
1684
|
+
get(_fields, name)._f.disabled);
|
1680
1685
|
if (!isBlurEvent || shouldDirty) {
|
1681
1686
|
if (_proxyFormState.isDirty) {
|
1682
1687
|
isPreviousDirty = _formState.isDirty;
|
@@ -2036,9 +2041,9 @@ function createFormControl(props = {}) {
|
|
2036
2041
|
const getFieldState = (name, formState) => ({
|
2037
2042
|
invalid: !!get((formState || _formState).errors, name),
|
2038
2043
|
isDirty: !!get((formState || _formState).dirtyFields, name),
|
2039
|
-
isTouched: !!get((formState || _formState).touchedFields, name),
|
2040
|
-
isValidating: !!get((formState || _formState).validatingFields, name),
|
2041
2044
|
error: get((formState || _formState).errors, name),
|
2045
|
+
isValidating: !!get(_formState.validatingFields, name),
|
2046
|
+
isTouched: !!get((formState || _formState).touchedFields, name),
|
2042
2047
|
});
|
2043
2048
|
const clearErrors = (name) => {
|
2044
2049
|
name &&
|
@@ -2049,7 +2054,11 @@ function createFormControl(props = {}) {
|
|
2049
2054
|
};
|
2050
2055
|
const setError = (name, error, options) => {
|
2051
2056
|
const ref = (get(_fields, name, { _f: {} })._f || {}).ref;
|
2057
|
+
const currentError = get(_formState.errors, name) || {};
|
2058
|
+
// Don't override existing error messages elsewhere in the object tree.
|
2059
|
+
const { ref: currentRef, message, type, ...restOfErrorTree } = currentError;
|
2052
2060
|
set(_formState.errors, name, {
|
2061
|
+
...restOfErrorTree,
|
2053
2062
|
...error,
|
2054
2063
|
ref,
|
2055
2064
|
});
|
@@ -2092,7 +2101,7 @@ function createFormControl(props = {}) {
|
|
2092
2101
|
!options.keepIsValid && _updateValid();
|
2093
2102
|
};
|
2094
2103
|
const _updateDisabledField = ({ disabled, name, field, fields, value, }) => {
|
2095
|
-
if (isBoolean(disabled)) {
|
2104
|
+
if ((isBoolean(disabled) && _state.mount) || !!disabled) {
|
2096
2105
|
const inputValue = disabled
|
2097
2106
|
? undefined
|
2098
2107
|
: isUndefined(value)
|
@@ -2192,12 +2201,15 @@ function createFormControl(props = {}) {
|
|
2192
2201
|
if (isBoolean(disabled)) {
|
2193
2202
|
_subjects.state.next({ disabled });
|
2194
2203
|
iterateFieldsByAction(_fields, (ref, name) => {
|
2195
|
-
let requiredDisabledState = disabled;
|
2196
2204
|
const currentField = get(_fields, name);
|
2197
|
-
if (currentField
|
2198
|
-
|
2205
|
+
if (currentField) {
|
2206
|
+
ref.disabled = currentField._f.disabled || disabled;
|
2207
|
+
if (Array.isArray(currentField._f.refs)) {
|
2208
|
+
currentField._f.refs.forEach((inputRef) => {
|
2209
|
+
inputRef.disabled = currentField._f.disabled || disabled;
|
2210
|
+
});
|
2211
|
+
}
|
2199
2212
|
}
|
2200
|
-
ref.disabled = requiredDisabledState;
|
2201
2213
|
}, 0, false);
|
2202
2214
|
}
|
2203
2215
|
};
|
@@ -2356,7 +2368,9 @@ function createFormControl(props = {}) {
|
|
2356
2368
|
: _formState.dirtyFields
|
2357
2369
|
: keepStateOptions.keepDefaultValues && formValues
|
2358
2370
|
? getDirtyFields(_defaultValues, formValues)
|
2359
|
-
:
|
2371
|
+
: keepStateOptions.keepDirty
|
2372
|
+
? _formState.dirtyFields
|
2373
|
+
: {},
|
2360
2374
|
touchedFields: keepStateOptions.keepTouched
|
2361
2375
|
? _formState.touchedFields
|
2362
2376
|
: {},
|