react-hook-form 7.19.0 → 7.19.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/README.md +12 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +15 -6
- package/dist/index.esm.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/useWatch.d.ts +3 -2
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
@@ -187,8 +187,8 @@ function useWatch(props) {
|
|
187
187
|
subject: control._subjects.watch,
|
188
188
|
callback: (formState) => {
|
189
189
|
if (shouldSubscribeByName(_name.current, formState.name)) {
|
190
|
-
const fieldValues = generateWatchOutput(_name.current, control._names, control._formValues);
|
191
|
-
updateValue(
|
190
|
+
const fieldValues = generateWatchOutput(_name.current, control._names, formState.values || control._formValues);
|
191
|
+
updateValue(isUndefined(_name.current)
|
192
192
|
? Object.assign({}, fieldValues) : Array.isArray(fieldValues)
|
193
193
|
? [...fieldValues]
|
194
194
|
: fieldValues);
|
@@ -232,7 +232,7 @@ function useController(props) {
|
|
232
232
|
if (isNameInFieldArray(control._names.array, name)
|
233
233
|
? _shouldUnregisterField && !control._stateFlags.action
|
234
234
|
: _shouldUnregisterField) {
|
235
|
-
control.unregister(name);
|
235
|
+
control.unregister(name, { keepDefaultValue: true });
|
236
236
|
}
|
237
237
|
else {
|
238
238
|
updateMounted(name, false);
|
@@ -431,7 +431,6 @@ const useFieldArray = (props) => {
|
|
431
431
|
const updatedFieldArrayValues = omitKeys(updatedFieldArrayValuesWithKey, keyName);
|
432
432
|
_actioned.current = true;
|
433
433
|
set(control._formValues, name, updatedFieldArrayValues);
|
434
|
-
setFields(updatedFieldArrayValuesWithKey);
|
435
434
|
return updatedFieldArrayValues;
|
436
435
|
}, [control, name, keyName]);
|
437
436
|
const append$1 = (value, options) => {
|
@@ -440,6 +439,7 @@ const useFieldArray = (props) => {
|
|
440
439
|
control._updateFieldArray(name, append, {
|
441
440
|
argA: fillEmptyArray(value),
|
442
441
|
}, updateValues(updatedFieldArrayValuesWithKey));
|
442
|
+
setFields(updatedFieldArrayValuesWithKey);
|
443
443
|
control._names.focus = getFocusFieldName(name, updatedFieldArrayValuesWithKey.length - appendValue.length, options);
|
444
444
|
};
|
445
445
|
const prepend$1 = (value, options) => {
|
@@ -447,6 +447,7 @@ const useFieldArray = (props) => {
|
|
447
447
|
control._updateFieldArray(name, prepend, {
|
448
448
|
argA: fillEmptyArray(value),
|
449
449
|
}, updateValues(updatedFieldArrayValuesWithKey));
|
450
|
+
setFields(updatedFieldArrayValuesWithKey);
|
450
451
|
control._names.focus = getFocusFieldName(name, 0, options);
|
451
452
|
};
|
452
453
|
const remove = (index) => {
|
@@ -454,6 +455,7 @@ const useFieldArray = (props) => {
|
|
454
455
|
control._updateFieldArray(name, removeArrayAt, {
|
455
456
|
argA: index,
|
456
457
|
}, updateValues(updatedFieldArrayValuesWithKey));
|
458
|
+
setFields(updatedFieldArrayValuesWithKey);
|
457
459
|
};
|
458
460
|
const insert$1 = (index, value, options) => {
|
459
461
|
const updatedFieldArrayValuesWithKey = insert(mapCurrentIds(control._getFieldArray(name), _fieldIds, keyName), index, mapIds(convertToArrayPayload(value), keyName));
|
@@ -461,6 +463,7 @@ const useFieldArray = (props) => {
|
|
461
463
|
argA: index,
|
462
464
|
argB: fillEmptyArray(value),
|
463
465
|
}, updateValues(updatedFieldArrayValuesWithKey));
|
466
|
+
setFields(updatedFieldArrayValuesWithKey);
|
464
467
|
control._names.focus = getFocusFieldName(name, index, options);
|
465
468
|
};
|
466
469
|
const swap = (indexA, indexB) => {
|
@@ -470,6 +473,7 @@ const useFieldArray = (props) => {
|
|
470
473
|
argA: indexA,
|
471
474
|
argB: indexB,
|
472
475
|
}, updateValues(updatedFieldArrayValuesWithKey), false);
|
476
|
+
setFields(updatedFieldArrayValuesWithKey);
|
473
477
|
};
|
474
478
|
const move = (from, to) => {
|
475
479
|
const updatedFieldArrayValuesWithKey = mapCurrentIds(control._getFieldArray(name), _fieldIds, keyName);
|
@@ -478,6 +482,7 @@ const useFieldArray = (props) => {
|
|
478
482
|
argA: from,
|
479
483
|
argB: to,
|
480
484
|
}, updateValues(updatedFieldArrayValuesWithKey), false);
|
485
|
+
setFields(updatedFieldArrayValuesWithKey);
|
481
486
|
};
|
482
487
|
const update = (index, value) => {
|
483
488
|
const updatedFieldArrayValuesWithKey = mapCurrentIds(control._getFieldArray(name), _fieldIds, keyName);
|
@@ -487,10 +492,12 @@ const useFieldArray = (props) => {
|
|
487
492
|
argA: index,
|
488
493
|
argB: value,
|
489
494
|
}, updateValues(_fieldIds.current), true, false);
|
495
|
+
setFields(_fieldIds.current);
|
490
496
|
};
|
491
497
|
const replace = (value) => {
|
492
498
|
const updatedFieldArrayValuesWithKey = mapIds(convertToArrayPayload(value), keyName);
|
493
499
|
control._updateFieldArray(name, () => updatedFieldArrayValuesWithKey, {}, updateValues(updatedFieldArrayValuesWithKey), true, false);
|
500
|
+
setFields(updatedFieldArrayValuesWithKey);
|
494
501
|
};
|
495
502
|
React.useEffect(() => {
|
496
503
|
control._stateFlags.action = false;
|
@@ -1526,6 +1533,7 @@ function createFormControl(props = {}) {
|
|
1526
1533
|
});
|
1527
1534
|
_names.mount.add(name);
|
1528
1535
|
!isUndefined(options.value) &&
|
1536
|
+
!options.disabled &&
|
1529
1537
|
set(_formValues, name, get(_formValues, name, options.value));
|
1530
1538
|
field
|
1531
1539
|
? isBoolean(options.disabled) &&
|
@@ -1582,7 +1590,9 @@ function createFormControl(props = {}) {
|
|
1582
1590
|
e.persist && e.persist();
|
1583
1591
|
}
|
1584
1592
|
let hasNoPromiseError = true;
|
1585
|
-
let fieldValues =
|
1593
|
+
let fieldValues = _options.shouldUnregister
|
1594
|
+
? cloneObject(_formValues)
|
1595
|
+
: Object.assign({}, _formValues);
|
1586
1596
|
_subjects.state.next({
|
1587
1597
|
isSubmitting: true,
|
1588
1598
|
});
|
@@ -1840,7 +1850,6 @@ function useForm(props = {}) {
|
|
1840
1850
|
}
|
1841
1851
|
control._removeUnmounted();
|
1842
1852
|
});
|
1843
|
-
React.useEffect(() => () => Object.values(control._subjects).forEach((subject) => subject.unsubscribe()), [control]);
|
1844
1853
|
_formControl.current.formState = getProxyFormState(formState, control._proxyFormState);
|
1845
1854
|
return _formControl.current;
|
1846
1855
|
}
|