react-hook-form 7.0.2 → 7.0.3

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.
package/dist/index.esm.js CHANGED
@@ -778,7 +778,7 @@ var validateField = async ({ _f: { ref, refs, required, maxLength, minLength, mi
778
778
  const isRadio = isRadioInput(ref);
779
779
  const isCheckBox = isCheckBoxInput(ref);
780
780
  const isRadioOrCheckbox = isRadio || isCheckBox;
781
- const isEmpty = !inputValue || (Array.isArray(inputValue) && !inputValue.length);
781
+ const isEmpty = inputValue === '' || (Array.isArray(inputValue) && !inputValue.length);
782
782
  const appendErrorsCurry = appendErrors.bind(null, name, validateAllFieldCriteria, error);
783
783
  const getMinMaxMessage = (exceedMax, maxLengthMessage, minLengthMessage, maxType = INPUT_VALIDATION_RULES.maxLength, minType = INPUT_VALIDATION_RULES.minLength) => {
784
784
  const message = exceedMax ? maxLengthMessage : minLengthMessage;
@@ -1212,6 +1212,9 @@ function useForm({ mode = VALIDATION_MODE.onSubmit, reValidateMode = VALIDATION_
1212
1212
  isDirty: getFormIsDirty(name, value),
1213
1213
  });
1214
1214
  }
1215
+ !value.length &&
1216
+ set(fieldsRef.current, name, []) &&
1217
+ set(fieldArrayDefaultValuesRef.current, name, []);
1215
1218
  }
1216
1219
  (field && !field._f) || isFieldArray
1217
1220
  ? setInternalValues(name, value, isFieldArray ? {} : options)
@@ -1426,13 +1429,15 @@ function useForm({ mode = VALIDATION_MODE.onSubmit, reValidateMode = VALIDATION_
1426
1429
  }
1427
1430
  };
1428
1431
  const register = React.useCallback((name, options) => {
1432
+ const isInitialRegister = !get(fieldsRef.current, name);
1429
1433
  set(fieldsRef.current, name, {
1430
- _f: Object.assign(Object.assign(Object.assign({}, (get(fieldsRef.current, name)
1431
- ? Object.assign({ ref: (get(fieldsRef.current, name)._f || {}).ref }, get(fieldsRef.current, name)._f) : { ref: { name } })), { name }), options),
1434
+ _f: Object.assign(Object.assign(Object.assign({}, (isInitialRegister
1435
+ ? { ref: { name } }
1436
+ : Object.assign({ ref: (get(fieldsRef.current, name)._f || {}).ref }, get(fieldsRef.current, name)._f))), { name }), options),
1432
1437
  });
1433
1438
  options && set(fieldsWithValidationRef.current, name, true);
1434
1439
  fieldsNamesRef.current.add(name);
1435
- updateValueAndGetDefault(name);
1440
+ isInitialRegister && updateValueAndGetDefault(name);
1436
1441
  return isWindowUndefined
1437
1442
  ? { name: name }
1438
1443
  : {