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
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 =
|
|
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({}, (
|
|
1431
|
-
?
|
|
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
|
: {
|