react-hook-form 7.54.1 → 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.
@@ -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
- if (isBoolean(disabled) && get(control._fields, name)) {
505
- control._updateDisabledField({
506
- disabled,
507
- fields: control._fields,
508
- name,
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,
@@ -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, disabled, } = field._f;
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 || disabled) {
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
- if (isBlurEvent) {
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, value, }) => {
2166
- if ((isBoolean(disabled) && _state.mount) || !!disabled) {
2167
- const inputValue = disabled
2168
- ? undefined
2169
- : isUndefined(value)
2170
- ? getFieldValue(field ? field._f : get(fields, name)._f)
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
- if (_options.disabled) {
2291
- if (onInvalid) {
2292
- await onInvalid({ ..._formState.errors }, e);
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: '',