react-hook-form 7.55.0-next.2 → 7.55.0-next.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 +22 -15
- 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/react-server.esm.mjs +11 -12
- package/dist/react-server.esm.mjs.map +1 -1
- package/dist/useController.d.ts.map +1 -1
- package/dist/useWatch.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 +12 -12
package/dist/index.esm.mjs
CHANGED
@@ -106,7 +106,6 @@ var set = (object, path, value) => {
|
|
106
106
|
object[key] = newValue;
|
107
107
|
object = object[key];
|
108
108
|
}
|
109
|
-
return object;
|
110
109
|
};
|
111
110
|
|
112
111
|
const EVENTS = {
|
@@ -315,6 +314,7 @@ function useWatch(props) {
|
|
315
314
|
const methods = useFormContext();
|
316
315
|
const { control = methods.control, name, defaultValue, disabled, exact, } = props || {};
|
317
316
|
const _name = React.useRef(name);
|
317
|
+
const _defaultValue = React.useRef(defaultValue);
|
318
318
|
_name.current = name;
|
319
319
|
React.useEffect(() => control._subscribe({
|
320
320
|
name: _name.current,
|
@@ -323,8 +323,8 @@ function useWatch(props) {
|
|
323
323
|
},
|
324
324
|
exact,
|
325
325
|
callback: (formState) => !disabled &&
|
326
|
-
updateValue(
|
327
|
-
}), [control,
|
326
|
+
updateValue(generateWatchOutput(_name.current, control._names, formState.values || control._formValues, false, _defaultValue.current)),
|
327
|
+
}), [control, disabled, exact]);
|
328
328
|
const [value, updateValue] = React.useState(control._getWatch(name, defaultValue));
|
329
329
|
React.useEffect(() => control._removeUnmounted());
|
330
330
|
return value;
|
@@ -369,6 +369,7 @@ function useController(props) {
|
|
369
369
|
name,
|
370
370
|
exact: true,
|
371
371
|
});
|
372
|
+
const _props = React.useRef(props);
|
372
373
|
const _registerProps = React.useRef(control.register(name, {
|
373
374
|
...props.rules,
|
374
375
|
value,
|
@@ -433,6 +434,12 @@ function useController(props) {
|
|
433
434
|
}), [name, disabled, formState.disabled, onChange, onBlur, ref, value]);
|
434
435
|
React.useEffect(() => {
|
435
436
|
const _shouldUnregisterField = control._options.shouldUnregister || shouldUnregister;
|
437
|
+
control.register(name, {
|
438
|
+
..._props.current.rules,
|
439
|
+
...(isBoolean(_props.current.disabled)
|
440
|
+
? { disabled: _props.current.disabled }
|
441
|
+
: {}),
|
442
|
+
});
|
436
443
|
const updateMounted = (name, value) => {
|
437
444
|
const field = get(control._fields, name);
|
438
445
|
if (field && field._f) {
|
@@ -1590,7 +1597,7 @@ function createFormControl(props = {}) {
|
|
1590
1597
|
if (!fieldReference.ref.type) {
|
1591
1598
|
_subjects.state.next({
|
1592
1599
|
name,
|
1593
|
-
values:
|
1600
|
+
values: cloneObject(_formValues),
|
1594
1601
|
});
|
1595
1602
|
}
|
1596
1603
|
}
|
@@ -1621,7 +1628,7 @@ function createFormControl(props = {}) {
|
|
1621
1628
|
if (isFieldArray) {
|
1622
1629
|
_subjects.array.next({
|
1623
1630
|
name,
|
1624
|
-
values:
|
1631
|
+
values: cloneObject(_formValues),
|
1625
1632
|
});
|
1626
1633
|
if ((_proxyFormState.isDirty ||
|
1627
1634
|
_proxyFormState.dirtyFields ||
|
@@ -1643,7 +1650,7 @@ function createFormControl(props = {}) {
|
|
1643
1650
|
isWatched(name, _names) && _subjects.state.next({ ..._formState });
|
1644
1651
|
_subjects.state.next({
|
1645
1652
|
name: _state.mount ? name : undefined,
|
1646
|
-
values:
|
1653
|
+
values: cloneObject(_formValues),
|
1647
1654
|
});
|
1648
1655
|
};
|
1649
1656
|
const onChange = async (event) => {
|
@@ -1685,7 +1692,7 @@ function createFormControl(props = {}) {
|
|
1685
1692
|
_subjects.state.next({
|
1686
1693
|
name,
|
1687
1694
|
type: event.type,
|
1688
|
-
values:
|
1695
|
+
values: cloneObject(_formValues),
|
1689
1696
|
});
|
1690
1697
|
if (shouldSkipValidation) {
|
1691
1698
|
if (_proxyFormState.isValid || _proxySubscribeFormState.isValid) {
|
@@ -1826,7 +1833,7 @@ function createFormControl(props = {}) {
|
|
1826
1833
|
if (shouldSubscribeByName(props.name, formState.name, props.exact) &&
|
1827
1834
|
shouldRenderFormState(formState, props.formState || _proxyFormState, _setFormState, props.reRenderRoot)) {
|
1828
1835
|
props.callback({
|
1829
|
-
values: _formValues,
|
1836
|
+
values: { ..._formValues },
|
1830
1837
|
..._formState,
|
1831
1838
|
...formState,
|
1832
1839
|
});
|
@@ -1862,7 +1869,7 @@ function createFormControl(props = {}) {
|
|
1862
1869
|
unset(_defaultValues, fieldName);
|
1863
1870
|
}
|
1864
1871
|
_subjects.state.next({
|
1865
|
-
values:
|
1872
|
+
values: cloneObject(_formValues),
|
1866
1873
|
});
|
1867
1874
|
_subjects.state.next({
|
1868
1875
|
..._formState,
|
@@ -1988,11 +1995,6 @@ function createFormControl(props = {}) {
|
|
1988
1995
|
e.persist && e.persist();
|
1989
1996
|
}
|
1990
1997
|
let fieldValues = cloneObject(_formValues);
|
1991
|
-
if (_names.disabled.size) {
|
1992
|
-
for (const name of _names.disabled) {
|
1993
|
-
set(fieldValues, name, undefined);
|
1994
|
-
}
|
1995
|
-
}
|
1996
1998
|
_subjects.state.next({
|
1997
1999
|
isSubmitting: true,
|
1998
2000
|
});
|
@@ -2004,6 +2006,11 @@ function createFormControl(props = {}) {
|
|
2004
2006
|
else {
|
2005
2007
|
await executeBuiltInValidation(_fields);
|
2006
2008
|
}
|
2009
|
+
if (_names.disabled.size) {
|
2010
|
+
for (const name of _names.disabled) {
|
2011
|
+
set(fieldValues, name, undefined);
|
2012
|
+
}
|
2013
|
+
}
|
2007
2014
|
unset(_formState.errors, 'root');
|
2008
2015
|
if (isEmptyObject(_formState.errors)) {
|
2009
2016
|
_subjects.state.next({
|
@@ -2526,7 +2533,7 @@ function useFieldArray(props) {
|
|
2526
2533
|
}
|
2527
2534
|
control._subjects.state.next({
|
2528
2535
|
name,
|
2529
|
-
values:
|
2536
|
+
values: cloneObject(control._formValues),
|
2530
2537
|
});
|
2531
2538
|
control._names.focus &&
|
2532
2539
|
iterateFieldsByAction(control._fields, (ref, key) => {
|