react-hook-form 7.19.0 → 7.19.1
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 +6 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +31 -28
- package/dist/index.esm.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
@@ -177,6 +177,33 @@ function generateWatchOutput(names, _names, formValues, isGlobal) {
|
|
177
177
|
return formValues;
|
178
178
|
}
|
179
179
|
|
180
|
+
var isKey = (value) => /^\w*$/.test(value);
|
181
|
+
|
182
|
+
var stringToPath = (input) => compact(input.replace(/["|']|\]/g, '').split(/\.|\[/));
|
183
|
+
|
184
|
+
function set(object, path, value) {
|
185
|
+
let index = -1;
|
186
|
+
const tempPath = isKey(path) ? [path] : stringToPath(path);
|
187
|
+
const length = tempPath.length;
|
188
|
+
const lastIndex = length - 1;
|
189
|
+
while (++index < length) {
|
190
|
+
const key = tempPath[index];
|
191
|
+
let newValue = value;
|
192
|
+
if (index !== lastIndex) {
|
193
|
+
const objValue = object[key];
|
194
|
+
newValue =
|
195
|
+
isObject(objValue) || Array.isArray(objValue)
|
196
|
+
? objValue
|
197
|
+
: !isNaN(+tempPath[index + 1])
|
198
|
+
? []
|
199
|
+
: {};
|
200
|
+
}
|
201
|
+
object[key] = newValue;
|
202
|
+
object = object[key];
|
203
|
+
}
|
204
|
+
return object;
|
205
|
+
}
|
206
|
+
|
180
207
|
function useWatch(props) {
|
181
208
|
const methods = useFormContext();
|
182
209
|
const { control = methods.control, name, defaultValue, disabled, } = props || {};
|
@@ -188,7 +215,9 @@ function useWatch(props) {
|
|
188
215
|
callback: (formState) => {
|
189
216
|
if (shouldSubscribeByName(_name.current, formState.name)) {
|
190
217
|
const fieldValues = generateWatchOutput(_name.current, control._names, control._formValues);
|
191
|
-
updateValue(isObject(fieldValues)
|
218
|
+
updateValue(isObject(fieldValues) &&
|
219
|
+
!(isString(_name.current) &&
|
220
|
+
get(control._fields, _name.current, {})._f)
|
192
221
|
? Object.assign({}, fieldValues) : Array.isArray(fieldValues)
|
193
222
|
? [...fieldValues]
|
194
223
|
: fieldValues);
|
@@ -287,33 +316,6 @@ const Controller = (props) => props.render(useController(props));
|
|
287
316
|
var appendErrors = (name, validateAllFieldCriteria, errors, type, message) => validateAllFieldCriteria
|
288
317
|
? Object.assign(Object.assign({}, errors[name]), { types: Object.assign(Object.assign({}, (errors[name] && errors[name].types ? errors[name].types : {})), { [type]: message || true }) }) : {};
|
289
318
|
|
290
|
-
var isKey = (value) => /^\w*$/.test(value);
|
291
|
-
|
292
|
-
var stringToPath = (input) => compact(input.replace(/["|']|\]/g, '').split(/\.|\[/));
|
293
|
-
|
294
|
-
function set(object, path, value) {
|
295
|
-
let index = -1;
|
296
|
-
const tempPath = isKey(path) ? [path] : stringToPath(path);
|
297
|
-
const length = tempPath.length;
|
298
|
-
const lastIndex = length - 1;
|
299
|
-
while (++index < length) {
|
300
|
-
const key = tempPath[index];
|
301
|
-
let newValue = value;
|
302
|
-
if (index !== lastIndex) {
|
303
|
-
const objValue = object[key];
|
304
|
-
newValue =
|
305
|
-
isObject(objValue) || Array.isArray(objValue)
|
306
|
-
? objValue
|
307
|
-
: !isNaN(+tempPath[index + 1])
|
308
|
-
? []
|
309
|
-
: {};
|
310
|
-
}
|
311
|
-
object[key] = newValue;
|
312
|
-
object = object[key];
|
313
|
-
}
|
314
|
-
return object;
|
315
|
-
}
|
316
|
-
|
317
319
|
const focusFieldBy = (fields, callback, fieldsNames) => {
|
318
320
|
for (const key of fieldsNames || Object.keys(fields)) {
|
319
321
|
const field = get(fields, key);
|
@@ -1526,6 +1528,7 @@ function createFormControl(props = {}) {
|
|
1526
1528
|
});
|
1527
1529
|
_names.mount.add(name);
|
1528
1530
|
!isUndefined(options.value) &&
|
1531
|
+
!options.disabled &&
|
1529
1532
|
set(_formValues, name, get(_formValues, name, options.value));
|
1530
1533
|
field
|
1531
1534
|
? isBoolean(options.disabled) &&
|