react-hook-form 7.54.0 → 7.54.2
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 +3 -0
- package/dist/controller.d.ts +1 -1
- package/dist/controller.d.ts.map +1 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.mjs +32 -46
- 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/logic/getFieldValue.d.ts.map +1 -1
- package/dist/logic/validateField.d.ts +2 -2
- package/dist/logic/validateField.d.ts.map +1 -1
- package/dist/types/form.d.ts +1 -0
- package/dist/types/form.d.ts.map +1 -1
- package/dist/useController.d.ts.map +1 -1
- package/dist/useFieldArray.d.ts.map +1 -1
- package/dist/useForm.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/index.esm.mjs
CHANGED
@@ -492,6 +492,7 @@ function useController(props) {
|
|
492
492
|
set(control._formValues, name, value);
|
493
493
|
}
|
494
494
|
}
|
495
|
+
!isArrayField && control.register(name);
|
495
496
|
return () => {
|
496
497
|
(isArrayField
|
497
498
|
? _shouldUnregisterField && !control._state.action
|
@@ -501,14 +502,11 @@ function useController(props) {
|
|
501
502
|
};
|
502
503
|
}, [name, control, isArrayField, shouldUnregister]);
|
503
504
|
React.useEffect(() => {
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
value: get(control._fields, name)._f.value,
|
510
|
-
});
|
511
|
-
}
|
505
|
+
control._updateDisabledField({
|
506
|
+
disabled,
|
507
|
+
fields: control._fields,
|
508
|
+
name,
|
509
|
+
});
|
512
510
|
}, [disabled, name, control]);
|
513
511
|
return React.useMemo(() => ({
|
514
512
|
field,
|
@@ -633,7 +631,7 @@ function Form(props) {
|
|
633
631
|
headers && headers['Content-Type'],
|
634
632
|
encType,
|
635
633
|
].some((value) => value && value.includes('json'));
|
636
|
-
const response = await fetch(action, {
|
634
|
+
const response = await fetch(String(action), {
|
637
635
|
method,
|
638
636
|
headers: {
|
639
637
|
...headers,
|
@@ -824,10 +822,10 @@ var getValueAndMessage = (validationData) => isObject(validationData) && !isRege
|
|
824
822
|
message: '',
|
825
823
|
};
|
826
824
|
|
827
|
-
var validateField = async (field, formValues, validateAllFieldCriteria, shouldUseNativeValidation, isFieldArray) => {
|
828
|
-
const { ref, refs, required, maxLength, minLength, min, max, pattern, validate, name, valueAsNumber, mount,
|
825
|
+
var validateField = async (field, disabledFieldNames, formValues, validateAllFieldCriteria, shouldUseNativeValidation, isFieldArray) => {
|
826
|
+
const { ref, refs, required, maxLength, minLength, min, max, pattern, validate, name, valueAsNumber, mount, } = field._f;
|
829
827
|
const inputValue = get(formValues, name);
|
830
|
-
if (!mount ||
|
828
|
+
if (!mount || disabledFieldNames.has(name)) {
|
831
829
|
return {};
|
832
830
|
}
|
833
831
|
const inputRef = refs ? refs[0] : ref;
|
@@ -1277,7 +1275,7 @@ function useFieldArray(props) {
|
|
1277
1275
|
field._f &&
|
1278
1276
|
!(getValidationModes(control._options.reValidateMode).isOnSubmit &&
|
1279
1277
|
getValidationModes(control._options.mode).isOnSubmit)) {
|
1280
|
-
validateField(field, control._formValues, control._options.criteriaMode === VALIDATION_MODE.all, control._options.shouldUseNativeValidation, true).then((error) => !isEmptyObject(error) &&
|
1278
|
+
validateField(field, control._names.disabled, control._formValues, control._options.criteriaMode === VALIDATION_MODE.all, control._options.shouldUseNativeValidation, true).then((error) => !isEmptyObject(error) &&
|
1281
1279
|
control._subjects.state.next({
|
1282
1280
|
errors: updateFieldArrayRootError(control._formState.errors, error, name),
|
1283
1281
|
}));
|
@@ -1458,9 +1456,6 @@ var getFieldValueAs = (value, { valueAsNumber, valueAsDate, setValueAs }) => isU
|
|
1458
1456
|
|
1459
1457
|
function getFieldValue(_f) {
|
1460
1458
|
const ref = _f.ref;
|
1461
|
-
if (_f.refs ? _f.refs.every((ref) => ref.disabled) : ref.disabled) {
|
1462
|
-
return;
|
1463
|
-
}
|
1464
1459
|
if (isFileInput(ref)) {
|
1465
1460
|
return ref.files;
|
1466
1461
|
}
|
@@ -1603,6 +1598,7 @@ function createFormControl(props = {}) {
|
|
1603
1598
|
};
|
1604
1599
|
let _names = {
|
1605
1600
|
mount: new Set(),
|
1601
|
+
disabled: new Set(),
|
1606
1602
|
unMount: new Set(),
|
1607
1603
|
array: new Set(),
|
1608
1604
|
watch: new Set(),
|
@@ -1825,7 +1821,7 @@ function createFormControl(props = {}) {
|
|
1825
1821
|
if (isPromiseFunction && _proxyFormState.validatingFields) {
|
1826
1822
|
_updateIsValidating([name], true);
|
1827
1823
|
}
|
1828
|
-
const fieldError = await validateField(field, _formValues, shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation && !shouldOnlyCheckValid, isFieldArrayRoot);
|
1824
|
+
const fieldError = await validateField(field, _names.disabled, _formValues, shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation && !shouldOnlyCheckValid, isFieldArrayRoot);
|
1829
1825
|
if (isPromiseFunction && _proxyFormState.validatingFields) {
|
1830
1826
|
_updateIsValidating([name]);
|
1831
1827
|
}
|
@@ -2004,12 +2000,10 @@ function createFormControl(props = {}) {
|
|
2004
2000
|
});
|
2005
2001
|
if (shouldSkipValidation) {
|
2006
2002
|
if (_proxyFormState.isValid) {
|
2007
|
-
if (_options.mode === 'onBlur') {
|
2008
|
-
|
2009
|
-
_updateValid();
|
2010
|
-
}
|
2003
|
+
if (_options.mode === 'onBlur' && isBlurEvent) {
|
2004
|
+
_updateValid();
|
2011
2005
|
}
|
2012
|
-
else {
|
2006
|
+
else if (!isBlurEvent) {
|
2013
2007
|
_updateValid();
|
2014
2008
|
}
|
2015
2009
|
}
|
@@ -2030,7 +2024,7 @@ function createFormControl(props = {}) {
|
|
2030
2024
|
}
|
2031
2025
|
else {
|
2032
2026
|
_updateIsValidating([name], true);
|
2033
|
-
error = (await validateField(field, _formValues, shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation))[name];
|
2027
|
+
error = (await validateField(field, _names.disabled, _formValues, shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation))[name];
|
2034
2028
|
_updateIsValidating([name]);
|
2035
2029
|
_updateIsFieldValueUpdated(fieldValue);
|
2036
2030
|
if (isFieldValueUpdated) {
|
@@ -2162,17 +2156,12 @@ function createFormControl(props = {}) {
|
|
2162
2156
|
});
|
2163
2157
|
!options.keepIsValid && _updateValid();
|
2164
2158
|
};
|
2165
|
-
const _updateDisabledField = ({ disabled, name, field, fields,
|
2166
|
-
if ((isBoolean(disabled) && _state.mount) ||
|
2167
|
-
|
2168
|
-
|
2169
|
-
|
2170
|
-
|
2171
|
-
: value;
|
2172
|
-
if (disabled || (!disabled && !isUndefined(inputValue))) {
|
2173
|
-
set(_formValues, name, inputValue);
|
2174
|
-
}
|
2175
|
-
updateTouchAndDirty(name, inputValue, false, false, true);
|
2159
|
+
const _updateDisabledField = ({ disabled, name, field, fields, }) => {
|
2160
|
+
if ((isBoolean(disabled) && _state.mount) ||
|
2161
|
+
!!disabled ||
|
2162
|
+
_names.disabled.has(name)) {
|
2163
|
+
disabled ? _names.disabled.add(name) : _names.disabled.delete(name);
|
2164
|
+
updateTouchAndDirty(name, getFieldValue(field ? field._f : get(fields, name)._f), false, false, true);
|
2176
2165
|
}
|
2177
2166
|
};
|
2178
2167
|
const register = (name, options = {}) => {
|
@@ -2195,7 +2184,6 @@ function createFormControl(props = {}) {
|
|
2195
2184
|
? options.disabled
|
2196
2185
|
: _options.disabled,
|
2197
2186
|
name,
|
2198
|
-
value: options.value,
|
2199
2187
|
});
|
2200
2188
|
}
|
2201
2189
|
else {
|
@@ -2287,13 +2275,12 @@ function createFormControl(props = {}) {
|
|
2287
2275
|
e.preventDefault && e.preventDefault();
|
2288
2276
|
e.persist && e.persist();
|
2289
2277
|
}
|
2290
|
-
|
2291
|
-
|
2292
|
-
|
2278
|
+
let fieldValues = cloneObject(_formValues);
|
2279
|
+
if (_names.disabled.size) {
|
2280
|
+
for (const name of _names.disabled) {
|
2281
|
+
set(fieldValues, name, undefined);
|
2293
2282
|
}
|
2294
|
-
return;
|
2295
2283
|
}
|
2296
|
-
let fieldValues = cloneObject(_formValues);
|
2297
2284
|
_subjects.state.next({
|
2298
2285
|
isSubmitting: true,
|
2299
2286
|
});
|
@@ -2416,6 +2403,7 @@ function createFormControl(props = {}) {
|
|
2416
2403
|
mount: keepStateOptions.keepDirtyValues ? _names.mount : new Set(),
|
2417
2404
|
unMount: new Set(),
|
2418
2405
|
array: new Set(),
|
2406
|
+
disabled: new Set(),
|
2419
2407
|
watch: new Set(),
|
2420
2408
|
watchAll: false,
|
2421
2409
|
focus: '',
|
@@ -2595,8 +2583,8 @@ function createFormControl(props = {}) {
|
|
2595
2583
|
* ```
|
2596
2584
|
*/
|
2597
2585
|
function useForm(props = {}) {
|
2598
|
-
const _formControl = React.useRef();
|
2599
|
-
const _values = React.useRef();
|
2586
|
+
const _formControl = React.useRef(undefined);
|
2587
|
+
const _values = React.useRef(undefined);
|
2600
2588
|
const [formState, updateFormState] = React.useState({
|
2601
2589
|
isDirty: false,
|
2602
2590
|
isValidating: false,
|
@@ -2674,10 +2662,8 @@ function useForm(props = {}) {
|
|
2674
2662
|
values: control._getWatch(),
|
2675
2663
|
});
|
2676
2664
|
}, [props.shouldUnregister, control]);
|
2677
|
-
|
2678
|
-
|
2679
|
-
formState: getProxyFormState(formState, control),
|
2680
|
-
}), [formState, control]);
|
2665
|
+
_formControl.current.formState = getProxyFormState(formState, control);
|
2666
|
+
return _formControl.current;
|
2681
2667
|
}
|
2682
2668
|
|
2683
2669
|
export { Controller, Form, FormProvider, appendErrors, get, set, useController, useFieldArray, useForm, useFormContext, useFormState, useWatch };
|