react-hook-form 7.51.0 → 7.51.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.
@@ -1354,8 +1354,6 @@ var isRadioOrCheckbox = (ref) => isRadioInput(ref) || isCheckBoxInput(ref);
1354
1354
 
1355
1355
  var live = (ref) => isHTMLElement(ref) && ref.isConnected;
1356
1356
 
1357
- var objectHasTruthyValue = (value) => isObject(value) && Object.values(value).some((val) => val);
1358
-
1359
1357
  var objectHasFunction = (data) => {
1360
1358
  for (const key in data) {
1361
1359
  if (isFunction(data[key])) {
@@ -1598,18 +1596,20 @@ function createFormControl(props = {}) {
1598
1596
  }
1599
1597
  }
1600
1598
  };
1601
- const _updateIsValidating = (isValidating, names) => {
1602
- if (!(_proxyFormState.isValidating || _proxyFormState.validatingFields)) {
1603
- return;
1599
+ const _updateIsValidating = (names, isValidating) => {
1600
+ if (_proxyFormState.isValidating || _proxyFormState.validatingFields) {
1601
+ (names || Array.from(_names.mount)).forEach((name) => {
1602
+ if (name) {
1603
+ isValidating
1604
+ ? set(_formState.validatingFields, name, isValidating)
1605
+ : unset(_formState.validatingFields, name);
1606
+ }
1607
+ });
1608
+ _subjects.state.next({
1609
+ validatingFields: _formState.validatingFields,
1610
+ isValidating: !isEmptyObject(_formState.validatingFields),
1611
+ });
1604
1612
  }
1605
- names.forEach((name) => {
1606
- set(_formState.validatingFields, name, isValidating);
1607
- });
1608
- _formState.isValidating = objectHasTruthyValue(_formState.validatingFields);
1609
- _subjects.state.next({
1610
- validatingFields: _formState.validatingFields,
1611
- isValidating: _formState.isValidating,
1612
- });
1613
1613
  };
1614
1614
  const _updateFieldArray = (name, values = [], method, args, shouldSetValues = true, shouldUpdateFieldsAndState = true) => {
1615
1615
  if (args && method) {
@@ -1739,9 +1739,13 @@ function createFormControl(props = {}) {
1739
1739
  };
1740
1740
  _subjects.state.next(updatedFormState);
1741
1741
  }
1742
- _updateIsValidating(false, Object.keys(_formState.validatingFields).filter((key) => key === name));
1743
1742
  };
1744
- const _executeSchema = async (name) => _options.resolver(_formValues, _options.context, getResolverOptions(name || _names.mount, _fields, _options.criteriaMode, _options.shouldUseNativeValidation));
1743
+ const _executeSchema = async (name) => {
1744
+ _updateIsValidating(name, true);
1745
+ const result = await _options.resolver(_formValues, _options.context, getResolverOptions(name || _names.mount, _fields, _options.criteriaMode, _options.shouldUseNativeValidation));
1746
+ _updateIsValidating(name);
1747
+ return result;
1748
+ };
1745
1749
  const executeSchemaAndUpdateState = async (names) => {
1746
1750
  const { errors } = await _executeSchema(names);
1747
1751
  if (names) {
@@ -1766,7 +1770,9 @@ function createFormControl(props = {}) {
1766
1770
  const { _f, ...fieldValue } = field;
1767
1771
  if (_f) {
1768
1772
  const isFieldArrayRoot = _names.array.has(_f.name);
1773
+ _updateIsValidating([name], true);
1769
1774
  const fieldError = await validateField(field, _formValues, shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation && !shouldOnlyCheckValid, isFieldArrayRoot);
1775
+ _updateIsValidating([name]);
1770
1776
  if (fieldError[_f.name]) {
1771
1777
  context.valid = false;
1772
1778
  if (shouldOnlyCheckValid) {
@@ -1943,7 +1949,6 @@ function createFormControl(props = {}) {
1943
1949
  _subjects.state.next({ name, ...(watched ? {} : fieldState) }));
1944
1950
  }
1945
1951
  !isBlurEvent && watched && _subjects.state.next({ ..._formState });
1946
- _updateIsValidating(true, [name]);
1947
1952
  if (_options.resolver) {
1948
1953
  const { errors } = await _executeSchema([name]);
1949
1954
  _updateIsFieldValueUpdated(fieldValue);
@@ -1956,7 +1961,9 @@ function createFormControl(props = {}) {
1956
1961
  }
1957
1962
  }
1958
1963
  else {
1964
+ _updateIsValidating([name], true);
1959
1965
  error = (await validateField(field, _formValues, shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation))[name];
1966
+ _updateIsValidating([name]);
1960
1967
  _updateIsFieldValueUpdated(fieldValue);
1961
1968
  if (isFieldValueUpdated) {
1962
1969
  if (error) {
@@ -1985,7 +1992,6 @@ function createFormControl(props = {}) {
1985
1992
  let isValid;
1986
1993
  let validationResult;
1987
1994
  const fieldNames = convertToArrayPayload(name);
1988
- _updateIsValidating(true, fieldNames);
1989
1995
  if (_options.resolver) {
1990
1996
  const errors = await executeSchemaAndUpdateState(isUndefined(name) ? name : fieldNames);
1991
1997
  isValid = isEmptyObject(errors);
@@ -2010,7 +2016,6 @@ function createFormControl(props = {}) {
2010
2016
  : { name }),
2011
2017
  ...(_options.resolver || !name ? { isValid } : {}),
2012
2018
  errors: _formState.errors,
2013
- isValidating: false,
2014
2019
  });
2015
2020
  options.shouldFocus &&
2016
2021
  !validationResult &&