react-hook-form 7.39.2 → 7.39.4
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/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.mjs +60 -61
- 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/getResolverOptions.d.ts +0 -1
- package/dist/logic/getResolverOptions.d.ts.map +1 -1
- package/dist/types/fields.d.ts +0 -1
- package/dist/types/fields.d.ts.map +1 -1
- package/dist/useController.d.ts.map +1 -1
- package/dist/useWatch.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.mjs
CHANGED
@@ -262,16 +262,41 @@ var generateWatchOutput = (names, _names, formValues, isGlobal) => {
|
|
262
262
|
return formValues;
|
263
263
|
};
|
264
264
|
|
265
|
-
var
|
265
|
+
var isPlainObject = (tempObject) => {
|
266
|
+
const prototypeCopy = tempObject.constructor && tempObject.constructor.prototype;
|
267
|
+
return (isObject(prototypeCopy) && prototypeCopy.hasOwnProperty('isPrototypeOf'));
|
268
|
+
};
|
266
269
|
|
267
|
-
var
|
268
|
-
|
269
|
-
|
270
|
-
|
270
|
+
var isWeb = typeof window !== 'undefined' &&
|
271
|
+
typeof window.HTMLElement !== 'undefined' &&
|
272
|
+
typeof document !== 'undefined';
|
273
|
+
|
274
|
+
function cloneObject(data) {
|
275
|
+
let copy;
|
276
|
+
const isArray = Array.isArray(data);
|
277
|
+
if (data instanceof Date) {
|
278
|
+
copy = new Date(data);
|
279
|
+
}
|
280
|
+
else if (data instanceof Set) {
|
281
|
+
copy = new Set(data);
|
282
|
+
}
|
283
|
+
else if (!(isWeb && (data instanceof Blob || data instanceof FileList)) &&
|
284
|
+
(isArray || isObject(data))) {
|
285
|
+
copy = isArray ? [] : {};
|
286
|
+
if (!Array.isArray(data) && !isPlainObject(data)) {
|
287
|
+
copy = data;
|
288
|
+
}
|
289
|
+
else {
|
290
|
+
for (const key in data) {
|
291
|
+
copy[key] = cloneObject(data[key]);
|
292
|
+
}
|
271
293
|
}
|
272
294
|
}
|
273
|
-
|
274
|
-
|
295
|
+
else {
|
296
|
+
return data;
|
297
|
+
}
|
298
|
+
return copy;
|
299
|
+
}
|
275
300
|
|
276
301
|
/**
|
277
302
|
* Custom hook to subscribe to field change and isolate re-rendering at the component level.
|
@@ -300,14 +325,11 @@ function useWatch(props) {
|
|
300
325
|
callback: React.useCallback((formState) => {
|
301
326
|
if (shouldSubscribeByName(_name.current, formState.name, exact)) {
|
302
327
|
const fieldValues = generateWatchOutput(_name.current, control._names, formState.values || control._formValues);
|
303
|
-
updateValue(isUndefined(_name.current) ||
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
: isUndefined(fieldValues)
|
309
|
-
? defaultValue
|
310
|
-
: fieldValues);
|
328
|
+
updateValue(isUndefined(_name.current) || !isUndefined(fieldValues)
|
329
|
+
? cloneObject(fieldValues)
|
330
|
+
: isUndefined(fieldValues)
|
331
|
+
? defaultValue
|
332
|
+
: fieldValues);
|
311
333
|
}
|
312
334
|
}, [control, exact, defaultValue]),
|
313
335
|
});
|
@@ -360,10 +382,6 @@ function useController(props) {
|
|
360
382
|
...props.rules,
|
361
383
|
value,
|
362
384
|
}));
|
363
|
-
const field = get(control._fields, name);
|
364
|
-
if (field) {
|
365
|
-
field._f._c = true;
|
366
|
-
}
|
367
385
|
React.useEffect(() => {
|
368
386
|
const updateMounted = (name, value) => {
|
369
387
|
const field = get(control._fields, name);
|
@@ -399,9 +417,15 @@ function useController(props) {
|
|
399
417
|
},
|
400
418
|
type: EVENTS.BLUR,
|
401
419
|
}), [name, control]),
|
402
|
-
ref: (
|
403
|
-
|
404
|
-
|
420
|
+
ref: (elm) => {
|
421
|
+
const field = get(control._fields, name);
|
422
|
+
if (field && elm) {
|
423
|
+
field._f.ref = {
|
424
|
+
focus: () => elm.focus(),
|
425
|
+
select: () => elm.select(),
|
426
|
+
setCustomValidity: (message) => elm.setCustomValidity(message),
|
427
|
+
reportValidity: () => elm.reportValidity(),
|
428
|
+
};
|
405
429
|
}
|
406
430
|
},
|
407
431
|
},
|
@@ -560,6 +584,8 @@ var isBoolean = (value) => typeof value === 'boolean';
|
|
560
584
|
|
561
585
|
var isFileInput = (element) => element.type === 'file';
|
562
586
|
|
587
|
+
var isFunction = (value) => typeof value === 'function';
|
588
|
+
|
563
589
|
var isMessage = (value) => isString(value) || React.isValidElement(value);
|
564
590
|
|
565
591
|
var isRadioInput = (element) => element.type === 'radio';
|
@@ -630,8 +656,8 @@ var validateField = async (field, inputValue, validateAllFieldCriteria, shouldUs
|
|
630
656
|
}
|
631
657
|
const inputRef = refs ? refs[0] : ref;
|
632
658
|
const setCustomValidity = (message) => {
|
633
|
-
if (shouldUseNativeValidation &&
|
634
|
-
inputRef.setCustomValidity(message);
|
659
|
+
if (shouldUseNativeValidation && inputRef.reportValidity) {
|
660
|
+
inputRef.setCustomValidity(isBoolean(message) ? '' : message || '');
|
635
661
|
inputRef.reportValidity();
|
636
662
|
}
|
637
663
|
};
|
@@ -802,42 +828,6 @@ function append(data, value) {
|
|
802
828
|
return [...data, ...convertToArrayPayload(value)];
|
803
829
|
}
|
804
830
|
|
805
|
-
var isPlainObject = (tempObject) => {
|
806
|
-
const prototypeCopy = tempObject.constructor && tempObject.constructor.prototype;
|
807
|
-
return (isObject(prototypeCopy) && prototypeCopy.hasOwnProperty('isPrototypeOf'));
|
808
|
-
};
|
809
|
-
|
810
|
-
var isWeb = typeof window !== 'undefined' &&
|
811
|
-
typeof window.HTMLElement !== 'undefined' &&
|
812
|
-
typeof document !== 'undefined';
|
813
|
-
|
814
|
-
function cloneObject(data) {
|
815
|
-
let copy;
|
816
|
-
const isArray = Array.isArray(data);
|
817
|
-
if (data instanceof Date) {
|
818
|
-
copy = new Date(data);
|
819
|
-
}
|
820
|
-
else if (data instanceof Set) {
|
821
|
-
copy = new Set(data);
|
822
|
-
}
|
823
|
-
else if (!(isWeb && (data instanceof Blob || data instanceof FileList)) &&
|
824
|
-
(isArray || isObject(data))) {
|
825
|
-
copy = isArray ? [] : {};
|
826
|
-
if (!Array.isArray(data) && !isPlainObject(data)) {
|
827
|
-
copy = data;
|
828
|
-
}
|
829
|
-
else {
|
830
|
-
for (const key in data) {
|
831
|
-
copy[key] = cloneObject(data[key]);
|
832
|
-
}
|
833
|
-
}
|
834
|
-
}
|
835
|
-
else {
|
836
|
-
return data;
|
837
|
-
}
|
838
|
-
return copy;
|
839
|
-
}
|
840
|
-
|
841
831
|
var fillEmptyArray = (value) => Array.isArray(value) ? value.map(() => undefined) : undefined;
|
842
832
|
|
843
833
|
var getValidationModes = (mode) => ({
|
@@ -1224,6 +1214,15 @@ var isRadioOrCheckbox = (ref) => isRadioInput(ref) || isCheckBoxInput(ref);
|
|
1224
1214
|
|
1225
1215
|
var live = (ref) => isHTMLElement(ref) && ref.isConnected;
|
1226
1216
|
|
1217
|
+
var objectHasFunction = (data) => {
|
1218
|
+
for (const key in data) {
|
1219
|
+
if (isFunction(data[key])) {
|
1220
|
+
return true;
|
1221
|
+
}
|
1222
|
+
}
|
1223
|
+
return false;
|
1224
|
+
};
|
1225
|
+
|
1227
1226
|
function markFieldsDirty(data, fields = {}) {
|
1228
1227
|
const isParentNodeArray = Array.isArray(data);
|
1229
1228
|
if (isObject(data) || isParentNodeArray) {
|
@@ -1689,7 +1688,7 @@ function createFormControl(props = {}) {
|
|
1689
1688
|
}
|
1690
1689
|
else {
|
1691
1690
|
fieldReference.ref.value = fieldValue;
|
1692
|
-
if (fieldReference.
|
1691
|
+
if (!fieldReference.ref.type) {
|
1693
1692
|
_subjects.watch.next({
|
1694
1693
|
name,
|
1695
1694
|
});
|