react-hook-form 7.38.0 → 7.39.0

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.
@@ -395,15 +395,10 @@ function useController(props) {
395
395
  },
396
396
  type: EVENTS.BLUR,
397
397
  }), [name, control]),
398
- ref: (elm) => {
398
+ ref: (ref) => {
399
399
  const field = get(control._fields, name);
400
- if (field && elm) {
401
- field._f.ref = {
402
- focus: () => elm.focus(),
403
- select: () => elm.select(),
404
- setCustomValidity: (message) => elm.setCustomValidity(message),
405
- reportValidity: () => elm.reportValidity(),
406
- };
400
+ if (field && ref) {
401
+ field._f.ref = ref;
407
402
  }
408
403
  },
409
404
  },
@@ -632,8 +627,8 @@ var validateField = async (field, inputValue, validateAllFieldCriteria, shouldUs
632
627
  }
633
628
  const inputRef = refs ? refs[0] : ref;
634
629
  const setCustomValidity = (message) => {
635
- if (shouldUseNativeValidation && inputRef.reportValidity) {
636
- inputRef.setCustomValidity(isBoolean(message) ? '' : message || ' ');
630
+ if (shouldUseNativeValidation && isString(message)) {
631
+ inputRef.setCustomValidity(message);
637
632
  inputRef.reportValidity();
638
633
  }
639
634
  };
@@ -1259,7 +1254,9 @@ function getDirtyFieldsFromDefaultValues(data, formValues, dirtyFieldsFromValues
1259
1254
  }
1260
1255
  }
1261
1256
  else {
1262
- dirtyFieldsFromValues[key] = !deepEqual(data[key], formValues[key]);
1257
+ deepEqual(data[key], formValues[key])
1258
+ ? delete dirtyFieldsFromValues[key]
1259
+ : (dirtyFieldsFromValues[key] = true);
1263
1260
  }
1264
1261
  }
1265
1262
  }
@@ -1442,13 +1439,13 @@ function createFormControl(props = {}) {
1442
1439
  clearTimeout(timer);
1443
1440
  timer = window.setTimeout(callback, wait);
1444
1441
  };
1445
- const _updateValid = async (shouldSkipRender) => {
1442
+ const _updateValid = async () => {
1446
1443
  let isValid = false;
1447
1444
  if (_proxyFormState.isValid) {
1448
1445
  isValid = _options.resolver
1449
1446
  ? isEmptyObject((await _executeSchema()).errors)
1450
1447
  : await executeBuiltInValidation(_fields, true);
1451
- if (!shouldSkipRender && isValid !== _formState.isValid) {
1448
+ if (isValid !== _formState.isValid) {
1452
1449
  _formState.isValid = isValid;
1453
1450
  _subjects.state.next({
1454
1451
  isValid,
@@ -1542,9 +1539,11 @@ function createFormControl(props = {}) {
1542
1539
  isFieldDirty && shouldRender && _subjects.state.next(output);
1543
1540
  return isFieldDirty ? output : {};
1544
1541
  };
1545
- const shouldRenderByError = async (name, isValid, error, fieldState) => {
1542
+ const shouldRenderByError = (name, isValid, error, fieldState) => {
1546
1543
  const previousFieldError = get(_formState.errors, name);
1547
- const shouldUpdateValid = _proxyFormState.isValid && _formState.isValid !== isValid;
1544
+ const shouldUpdateValid = _proxyFormState.isValid &&
1545
+ isBoolean(isValid) &&
1546
+ _formState.isValid !== isValid;
1548
1547
  if (props.delayError && error) {
1549
1548
  delayErrorCallback = debounce(() => updateErrors(name, error));
1550
1549
  delayErrorCallback(props.delayError);
@@ -1561,7 +1560,7 @@ function createFormControl(props = {}) {
1561
1560
  shouldUpdateValid) {
1562
1561
  const updatedFormState = {
1563
1562
  ...fieldState,
1564
- ...(shouldUpdateValid ? { isValid } : {}),
1563
+ ...(shouldUpdateValid && isBoolean(isValid) ? { isValid } : {}),
1565
1564
  errors: _formState.errors,
1566
1565
  name,
1567
1566
  };
@@ -1775,11 +1774,14 @@ function createFormControl(props = {}) {
1775
1774
  type: event.type,
1776
1775
  });
1777
1776
  if (shouldSkipValidation) {
1777
+ _proxyFormState.isValid && _updateValid();
1778
1778
  return (shouldRender &&
1779
1779
  _subjects.state.next({ name, ...(watched ? {} : fieldState) }));
1780
1780
  }
1781
1781
  !isBlurEvent && watched && _subjects.state.next({});
1782
- validateFields[name] = validateFields[name] ? +1 : 1;
1782
+ validateFields[name] = validateFields[name]
1783
+ ? validateFields[name] + 1
1784
+ : 1;
1783
1785
  _subjects.state.next({
1784
1786
  isValidating: true,
1785
1787
  });
@@ -1793,7 +1795,7 @@ function createFormControl(props = {}) {
1793
1795
  }
1794
1796
  else {
1795
1797
  error = (await validateField(field, get(_formValues, name), shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation))[name];
1796
- isValid = await _updateValid(true);
1798
+ _updateValid();
1797
1799
  }
1798
1800
  field._f.deps &&
1799
1801
  trigger(field._f.deps);
@@ -2086,13 +2088,13 @@ function createFormControl(props = {}) {
2086
2088
  const fieldReference = Array.isArray(field._f.refs)
2087
2089
  ? field._f.refs[0]
2088
2090
  : field._f.ref;
2089
- try {
2090
- if (isHTMLElement(fieldReference)) {
2091
- fieldReference.closest('form').reset();
2091
+ if (isHTMLElement(fieldReference)) {
2092
+ const form = fieldReference.closest('form');
2093
+ if (form) {
2094
+ form.reset();
2092
2095
  break;
2093
2096
  }
2094
2097
  }
2095
- catch (_a) { }
2096
2098
  }
2097
2099
  }
2098
2100
  }