react-hook-form 7.27.0 → 7.28.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.
@@ -733,13 +733,14 @@ function useFieldArray(props) {
733
733
  }, false);
734
734
  };
735
735
  const update = (index, value) => {
736
- const updatedFieldArrayValues = updateAt(control._getFieldArray(name), index, value);
736
+ const updateValue = cloneObject(value);
737
+ const updatedFieldArrayValues = updateAt(control._getFieldArray(name), index, updateValue);
737
738
  ids.current = [...updatedFieldArrayValues].map((item, i) => !item || i === index ? generateId() : ids.current[i]);
738
739
  updateValues(updatedFieldArrayValues);
739
740
  setFields([...updatedFieldArrayValues]);
740
741
  control._updateFieldArray(name, updatedFieldArrayValues, updateAt, {
741
742
  argA: index,
742
- argB: value,
743
+ argB: updateValue,
743
744
  }, true, false);
744
745
  };
745
746
  const replace = (value) => {
@@ -909,7 +910,7 @@ function unset(object, path) {
909
910
  if (currentPathsLength === index &&
910
911
  ((isObject(objectRef) && isEmptyObject(objectRef)) ||
911
912
  (Array.isArray(objectRef) &&
912
- !objectRef.filter((data) => (isObject(data) && !isEmptyObject(data)) || isBoolean(data)).length))) {
913
+ !objectRef.filter((data) => !isUndefined(data)).length))) {
913
914
  previousObjRef ? delete previousObjRef[item] : delete object[item];
914
915
  }
915
916
  previousObjRef = objectRef;
@@ -1342,21 +1343,22 @@ function createFormControl(props = {}) {
1342
1343
  }
1343
1344
  return isValid;
1344
1345
  };
1345
- const _updateFieldArray = (name, values = [], method, args, shouldSetValues = true, shouldUpdateFieldsAndErrors = true) => {
1346
+ const _updateFieldArray = (name, values = [], method, args, shouldSetValues = true, shouldUpdateFieldsAndState = true) => {
1346
1347
  if (args && method) {
1347
1348
  _stateFlags.action = true;
1348
- if (shouldUpdateFieldsAndErrors && Array.isArray(get(_fields, name))) {
1349
+ if (shouldUpdateFieldsAndState && Array.isArray(get(_fields, name))) {
1349
1350
  const fieldValues = method(get(_fields, name), args.argA, args.argB);
1350
1351
  shouldSetValues && set(_fields, name, fieldValues);
1351
1352
  }
1352
1353
  if (_proxyFormState.errors &&
1353
- shouldUpdateFieldsAndErrors &&
1354
+ shouldUpdateFieldsAndState &&
1354
1355
  Array.isArray(get(_formState.errors, name))) {
1355
1356
  const errors = method(get(_formState.errors, name), args.argA, args.argB);
1356
1357
  shouldSetValues && set(_formState.errors, name, errors);
1357
1358
  unsetEmptyArray(_formState.errors, name);
1358
1359
  }
1359
1360
  if (_proxyFormState.touchedFields &&
1361
+ shouldUpdateFieldsAndState &&
1360
1362
  Array.isArray(get(_formState.touchedFields, name))) {
1361
1363
  const touchedFields = method(get(_formState.touchedFields, name), args.argA, args.argB);
1362
1364
  shouldSetValues && set(_formState.touchedFields, name, touchedFields);
@@ -1665,7 +1667,8 @@ function createFormControl(props = {}) {
1665
1667
  error = (await validateField(field, get(_formValues, name), shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation))[name];
1666
1668
  isValid = await _updateValid(true);
1667
1669
  }
1668
- field._f.deps && trigger(field._f.deps);
1670
+ field._f.deps &&
1671
+ trigger(field._f.deps);
1669
1672
  shouldRenderByError(false, name, isValid, error, fieldState);
1670
1673
  }
1671
1674
  };
@@ -1802,7 +1805,7 @@ function createFormControl(props = {}) {
1802
1805
  set(_fields, name, {
1803
1806
  _f: Object.assign(Object.assign({}, field._f), (radioOrCheckbox
1804
1807
  ? {
1805
- refs: refs.concat(fieldRef).filter(live),
1808
+ refs: [...refs.filter(live), fieldRef],
1806
1809
  ref: { type: fieldRef.type, name },
1807
1810
  }
1808
1811
  : { ref: fieldRef })),