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.cjs.development.js +9 -4
- package/dist/index.cjs.development.js.map +1 -1
- package/dist/index.cjs.production.min.js +1 -1
- package/dist/index.cjs.production.min.js.map +1 -1
- package/dist/index.esm.js +9 -4
- package/dist/index.esm.js.map +1 -1
- package/dist/index.umd.development.js +9 -4
- package/dist/index.umd.development.js.map +1 -1
- package/dist/index.umd.production.min.js +1 -1
- package/dist/index.umd.production.min.js.map +1 -1
- package/package.json +1 -1
@@ -804,7 +804,7 @@ var validateField = async ({ _f: { ref, refs, required, maxLength, minLength, mi
|
|
804
804
|
const isRadio = isRadioInput(ref);
|
805
805
|
const isCheckBox = isCheckBoxInput(ref);
|
806
806
|
const isRadioOrCheckbox = isRadio || isCheckBox;
|
807
|
-
const isEmpty =
|
807
|
+
const isEmpty = inputValue === '' || (Array.isArray(inputValue) && !inputValue.length);
|
808
808
|
const appendErrorsCurry = appendErrors.bind(null, name, validateAllFieldCriteria, error);
|
809
809
|
const getMinMaxMessage = (exceedMax, maxLengthMessage, minLengthMessage, maxType = INPUT_VALIDATION_RULES.maxLength, minType = INPUT_VALIDATION_RULES.minLength) => {
|
810
810
|
const message = exceedMax ? maxLengthMessage : minLengthMessage;
|
@@ -1238,6 +1238,9 @@ function useForm({ mode = VALIDATION_MODE.onSubmit, reValidateMode = VALIDATION_
|
|
1238
1238
|
isDirty: getFormIsDirty(name, value),
|
1239
1239
|
});
|
1240
1240
|
}
|
1241
|
+
!value.length &&
|
1242
|
+
set(fieldsRef.current, name, []) &&
|
1243
|
+
set(fieldArrayDefaultValuesRef.current, name, []);
|
1241
1244
|
}
|
1242
1245
|
(field && !field._f) || isFieldArray
|
1243
1246
|
? setInternalValues(name, value, isFieldArray ? {} : options)
|
@@ -1452,13 +1455,15 @@ function useForm({ mode = VALIDATION_MODE.onSubmit, reValidateMode = VALIDATION_
|
|
1452
1455
|
}
|
1453
1456
|
};
|
1454
1457
|
const register = React__namespace.useCallback((name, options) => {
|
1458
|
+
const isInitialRegister = !get(fieldsRef.current, name);
|
1455
1459
|
set(fieldsRef.current, name, {
|
1456
|
-
_f: Object.assign(Object.assign(Object.assign({}, (
|
1457
|
-
?
|
1460
|
+
_f: Object.assign(Object.assign(Object.assign({}, (isInitialRegister
|
1461
|
+
? { ref: { name } }
|
1462
|
+
: Object.assign({ ref: (get(fieldsRef.current, name)._f || {}).ref }, get(fieldsRef.current, name)._f))), { name }), options),
|
1458
1463
|
});
|
1459
1464
|
options && set(fieldsWithValidationRef.current, name, true);
|
1460
1465
|
fieldsNamesRef.current.add(name);
|
1461
|
-
updateValueAndGetDefault(name);
|
1466
|
+
isInitialRegister && updateValueAndGetDefault(name);
|
1462
1467
|
return isWindowUndefined
|
1463
1468
|
? { name: name }
|
1464
1469
|
: {
|