react-hook-form 7.42.0-next.0 → 7.42.1

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.
@@ -148,7 +148,8 @@ var getProxyFormState = (formState, control, localProxyFormState, isRoot = true)
148
148
 
149
149
  var isEmptyObject = (value) => isObject(value) && !Object.keys(value).length;
150
150
 
151
- var shouldRenderFormState = (formStateData, _proxyFormState, isRoot) => {
151
+ var shouldRenderFormState = (formStateData, _proxyFormState, updateFormState, isRoot) => {
152
+ updateFormState(formStateData);
152
153
  const { name, ...formState } = formStateData;
153
154
  return (isEmptyObject(formState) ||
154
155
  Object.keys(formState).length >= Object.keys(_proxyFormState).length ||
@@ -231,7 +232,7 @@ function useFormState(props) {
231
232
  disabled,
232
233
  next: (value) => _mounted.current &&
233
234
  shouldSubscribeByName(_name.current, value.name, exact) &&
234
- shouldRenderFormState(value, _localProxyFormState.current) &&
235
+ shouldRenderFormState(value, _localProxyFormState.current, control._updateFormState) &&
235
236
  updateFormState({
236
237
  ...control._formState,
237
238
  ...value,
@@ -246,7 +247,7 @@ function useFormState(props) {
246
247
  isDirty,
247
248
  });
248
249
  }
249
- control._updateValid();
250
+ _localProxyFormState.current.isValid && control._updateValid(true);
250
251
  return () => {
251
252
  _mounted.current = false;
252
253
  };
@@ -593,6 +594,15 @@ var isFileInput = (element) => element.type === 'file';
593
594
 
594
595
  var isFunction = (value) => typeof value === 'function';
595
596
 
597
+ var isHTMLElement = (value) => {
598
+ if (!isWeb) {
599
+ return false;
600
+ }
601
+ const owner = value ? value.ownerDocument : 0;
602
+ return (value instanceof
603
+ (owner && owner.defaultView ? owner.defaultView.HTMLElement : HTMLElement));
604
+ };
605
+
596
606
  var isMessage = (value) => isString(value) || React.isValidElement(value);
597
607
 
598
608
  var isRadioInput = (element) => element.type === 'radio';
@@ -676,8 +686,8 @@ var validateField = async (field, formValues, validateAllFieldCriteria, shouldUs
676
686
  const isEmpty = ((valueAsNumber || isFileInput(ref)) &&
677
687
  isUndefined(ref.value) &&
678
688
  isUndefined(inputValue)) ||
689
+ (isHTMLElement(ref) && ref.value === '') ||
679
690
  inputValue === '' ||
680
- ref.value === '' ||
681
691
  (Array.isArray(inputValue) && !inputValue.length);
682
692
  const appendErrorsCurry = appendErrors.bind(null, name, validateAllFieldCriteria, error);
683
693
  const getMinMaxMessage = (exceedMax, maxLengthMessage, minLengthMessage, maxType = INPUT_VALIDATION_RULES.maxLength, minType = INPUT_VALIDATION_RULES.minLength) => {
@@ -1108,7 +1118,7 @@ function useFieldArray(props) {
1108
1118
  control._names.focus &&
1109
1119
  focusFieldBy(control._fields, (key) => !!key && key.startsWith(control._names.focus || ''));
1110
1120
  control._names.focus = '';
1111
- control._proxyFormState.isValid && control._updateValid();
1121
+ control._updateValid();
1112
1122
  }, [fields, name, control]);
1113
1123
  React.useEffect(() => {
1114
1124
  !get(control._formValues, name) && control._updateFieldArray(name);
@@ -1194,12 +1204,6 @@ function deepEqual(object1, object2) {
1194
1204
  return true;
1195
1205
  }
1196
1206
 
1197
- var isHTMLElement = (value) => {
1198
- const owner = value ? value.ownerDocument : 0;
1199
- return (value instanceof
1200
- (owner && owner.defaultView ? owner.defaultView.HTMLElement : HTMLElement));
1201
- };
1202
-
1203
1207
  var isMultipleSelect = (element) => element.type === `select-multiple`;
1204
1208
 
1205
1209
  var isRadioOrCheckbox = (ref) => isRadioInput(ref) || isCheckBoxInput(ref);
@@ -1436,8 +1440,8 @@ function createFormControl(props = {}, flushRootRender) {
1436
1440
  clearTimeout(timer);
1437
1441
  timer = window.setTimeout(callback, wait);
1438
1442
  };
1439
- const _updateValid = async () => {
1440
- if (_proxyFormState.isValid) {
1443
+ const _updateValid = async (shouldUpdateValid) => {
1444
+ if (_proxyFormState.isValid || shouldUpdateValid) {
1441
1445
  const isValid = _options.resolver
1442
1446
  ? isEmptyObject((await _executeSchema()).errors)
1443
1447
  : await executeBuiltInValidation(_fields, true);
@@ -1652,7 +1656,7 @@ function createFormControl(props = {}, flushRootRender) {
1652
1656
  !fieldReference.disabled &&
1653
1657
  set(_formValues, name, getFieldValueAs(value, fieldReference));
1654
1658
  fieldValue =
1655
- isWeb && isHTMLElement(fieldReference.ref) && isNullOrUndefined(value)
1659
+ isHTMLElement(fieldReference.ref) && isNullOrUndefined(value)
1656
1660
  ? ''
1657
1661
  : value;
1658
1662
  if (isMultipleSelect(fieldReference.ref)) {
@@ -2140,6 +2144,12 @@ function createFormControl(props = {}, flushRootRender) {
2140
2144
  }
2141
2145
  }
2142
2146
  };
2147
+ const _updateFormState = (updatedFormState) => {
2148
+ _formState = {
2149
+ ..._formState,
2150
+ ...updatedFormState,
2151
+ };
2152
+ };
2143
2153
  if (isFunction(_options.defaultValues)) {
2144
2154
  _options.defaultValues().then((values) => {
2145
2155
  reset(values, _options.resetOptions);
@@ -2162,6 +2172,7 @@ function createFormControl(props = {}, flushRootRender) {
2162
2172
  _updateFieldArray,
2163
2173
  _getFieldArray,
2164
2174
  _reset,
2175
+ _updateFormState,
2165
2176
  _subjects,
2166
2177
  _proxyFormState,
2167
2178
  get _fields() {
@@ -2275,18 +2286,14 @@ function useForm(props = {}) {
2275
2286
  useSubscribe({
2276
2287
  subject: control._subjects.state,
2277
2288
  next: (value) => {
2278
- if (shouldRenderFormState(value, control._proxyFormState, true)) {
2279
- control._formState = {
2280
- ...control._formState,
2281
- ...value,
2282
- };
2289
+ if (shouldRenderFormState(value, control._proxyFormState, control._updateFormState, true)) {
2283
2290
  updateFormState({ ...control._formState });
2284
2291
  }
2285
2292
  },
2286
2293
  });
2287
2294
  React.useEffect(() => {
2288
2295
  if (!control._stateFlags.mount) {
2289
- control._proxyFormState.isValid && control._updateValid();
2296
+ control._updateValid();
2290
2297
  control._stateFlags.mount = true;
2291
2298
  }
2292
2299
  if (control._stateFlags.watch) {