react-hook-form 7.41.2 → 7.42.0-next.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.
- package/dist/controller.d.ts +1 -1
- package/dist/controller.d.ts.map +1 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.mjs +42 -63
- package/dist/index.esm.mjs.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/logic/createFormControl.d.ts.map +1 -1
- package/dist/logic/getResolverOptions.d.ts +1 -1
- package/dist/logic/hasValidation.d.ts +1 -1
- package/dist/logic/updateFieldArrayRootError.d.ts +1 -1
- package/dist/logic/updateFieldArrayRootError.d.ts.map +1 -1
- package/dist/logic/validateField.d.ts +2 -2
- package/dist/logic/validateField.d.ts.map +1 -1
- package/dist/types/errors.d.ts +2 -2
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/fieldArray.d.ts +1 -1
- package/dist/types/fieldArray.d.ts.map +1 -1
- package/dist/types/form.d.ts +6 -6
- package/dist/types/form.d.ts.map +1 -1
- package/dist/types/path/eager.d.ts +44 -18
- package/dist/types/path/eager.d.ts.map +1 -1
- package/dist/types/utils.d.ts +15 -1
- package/dist/types/utils.d.ts.map +1 -1
- package/dist/types/validator.d.ts +2 -2
- package/dist/types/validator.d.ts.map +1 -1
- package/dist/utils/unset.d.ts +1 -1
- package/dist/utils/unset.d.ts.map +1 -1
- package/package.json +19 -19
- package/dist/tsdoc-metadata.json +0 -11
package/dist/index.esm.mjs
CHANGED
@@ -656,8 +656,9 @@ var getValueAndMessage = (validationData) => isObject(validationData) && !isRege
|
|
656
656
|
message: '',
|
657
657
|
};
|
658
658
|
|
659
|
-
var validateField = async (field,
|
659
|
+
var validateField = async (field, formValues, validateAllFieldCriteria, shouldUseNativeValidation, isFieldArray) => {
|
660
660
|
const { ref, refs, required, maxLength, minLength, min, max, pattern, validate, name, valueAsNumber, mount, disabled, } = field._f;
|
661
|
+
const inputValue = get(formValues, name);
|
661
662
|
if (!mount || disabled) {
|
662
663
|
return {};
|
663
664
|
}
|
@@ -788,7 +789,7 @@ var validateField = async (field, inputValue, validateAllFieldCriteria, shouldUs
|
|
788
789
|
}
|
789
790
|
if (validate) {
|
790
791
|
if (isFunction(validate)) {
|
791
|
-
const result = await validate(inputValue);
|
792
|
+
const result = await validate(inputValue, formValues);
|
792
793
|
const validateError = getValidateError(result, inputRef);
|
793
794
|
if (validateError) {
|
794
795
|
error[name] = {
|
@@ -807,7 +808,7 @@ var validateField = async (field, inputValue, validateAllFieldCriteria, shouldUs
|
|
807
808
|
if (!isEmptyObject(validationResult) && !validateAllFieldCriteria) {
|
808
809
|
break;
|
809
810
|
}
|
810
|
-
const validateError = getValidateError(await validate[key](inputValue), inputRef, key);
|
811
|
+
const validateError = getValidateError(await validate[key](inputValue, formValues), inputRef, key);
|
811
812
|
if (validateError) {
|
812
813
|
validationResult = {
|
813
814
|
...validateError,
|
@@ -897,31 +898,21 @@ function isEmptyArray(obj) {
|
|
897
898
|
return true;
|
898
899
|
}
|
899
900
|
function unset(object, path) {
|
900
|
-
const
|
901
|
-
|
902
|
-
|
903
|
-
|
901
|
+
const paths = Array.isArray(path)
|
902
|
+
? path
|
903
|
+
: isKey(path)
|
904
|
+
? [path]
|
905
|
+
: stringToPath(path);
|
906
|
+
const childObject = paths.length === 1 ? object : baseGet(object, paths);
|
907
|
+
const index = paths.length - 1;
|
908
|
+
const key = paths[index];
|
904
909
|
if (childObject) {
|
905
910
|
delete childObject[key];
|
906
911
|
}
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
const currentPathsLength = currentPaths.length - 1;
|
912
|
-
if (k > 0) {
|
913
|
-
previousObjRef = object;
|
914
|
-
}
|
915
|
-
while (++index < currentPaths.length) {
|
916
|
-
const item = currentPaths[index];
|
917
|
-
objectRef = objectRef ? objectRef[item] : object[item];
|
918
|
-
if (currentPathsLength === index &&
|
919
|
-
((isObject(objectRef) && isEmptyObject(objectRef)) ||
|
920
|
-
(Array.isArray(objectRef) && isEmptyArray(objectRef)))) {
|
921
|
-
previousObjRef ? delete previousObjRef[item] : delete object[item];
|
922
|
-
}
|
923
|
-
previousObjRef = objectRef;
|
924
|
-
}
|
912
|
+
if (index !== 0 &&
|
913
|
+
((isObject(childObject) && isEmptyObject(childObject)) ||
|
914
|
+
(Array.isArray(childObject) && isEmptyArray(childObject)))) {
|
915
|
+
unset(object, paths.slice(0, -1));
|
925
916
|
}
|
926
917
|
return object;
|
927
918
|
}
|
@@ -1103,7 +1094,7 @@ function useFieldArray(props) {
|
|
1103
1094
|
else {
|
1104
1095
|
const field = get(control._fields, name);
|
1105
1096
|
if (field && field._f) {
|
1106
|
-
validateField(field,
|
1097
|
+
validateField(field, control._formValues, control._options.criteriaMode === VALIDATION_MODE.all, control._options.shouldUseNativeValidation, true).then((error) => !isEmptyObject(error) &&
|
1107
1098
|
control._subjects.state.next({
|
1108
1099
|
errors: updateFieldArrayRootError(control._formState.errors, error, name),
|
1109
1100
|
}));
|
@@ -1609,7 +1600,7 @@ function createFormControl(props = {}, flushRootRender) {
|
|
1609
1600
|
const { _f, ...fieldValue } = field;
|
1610
1601
|
if (_f) {
|
1611
1602
|
const isFieldArrayRoot = _names.array.has(_f.name);
|
1612
|
-
const fieldError = await validateField(field,
|
1603
|
+
const fieldError = await validateField(field, _formValues, shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation, isFieldArrayRoot);
|
1613
1604
|
if (fieldError[_f.name]) {
|
1614
1605
|
context.valid = false;
|
1615
1606
|
if (shouldOnlyCheckValid) {
|
@@ -1696,8 +1687,7 @@ function createFormControl(props = {}, flushRootRender) {
|
|
1696
1687
|
}
|
1697
1688
|
(options.shouldDirty || options.shouldTouch) &&
|
1698
1689
|
updateTouchAndDirty(name, fieldValue, options.shouldTouch, options.shouldDirty, true);
|
1699
|
-
options.shouldValidate &&
|
1700
|
-
trigger(name);
|
1690
|
+
options.shouldValidate && trigger(name);
|
1701
1691
|
};
|
1702
1692
|
const setValues = (name, value, options) => {
|
1703
1693
|
for (const fieldKey in value) {
|
@@ -1790,7 +1780,7 @@ function createFormControl(props = {}, flushRootRender) {
|
|
1790
1780
|
isValid = isEmptyObject(errors);
|
1791
1781
|
}
|
1792
1782
|
else {
|
1793
|
-
error = (await validateField(field,
|
1783
|
+
error = (await validateField(field, _formValues, shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation))[name];
|
1794
1784
|
if (error) {
|
1795
1785
|
isValid = false;
|
1796
1786
|
}
|
@@ -1992,48 +1982,37 @@ function createFormControl(props = {}, flushRootRender) {
|
|
1992
1982
|
e.preventDefault && e.preventDefault();
|
1993
1983
|
e.persist && e.persist();
|
1994
1984
|
}
|
1995
|
-
let hasNoPromiseError = true;
|
1996
1985
|
let fieldValues = cloneObject(_formValues);
|
1997
1986
|
_subjects.state.next({
|
1998
1987
|
isSubmitting: true,
|
1999
1988
|
});
|
2000
|
-
|
2001
|
-
|
2002
|
-
|
2003
|
-
|
2004
|
-
fieldValues = values;
|
2005
|
-
}
|
2006
|
-
else {
|
2007
|
-
await executeBuiltInValidation(_fields);
|
2008
|
-
}
|
2009
|
-
if (isEmptyObject(_formState.errors)) {
|
2010
|
-
_subjects.state.next({
|
2011
|
-
errors: {},
|
2012
|
-
isSubmitting: true,
|
2013
|
-
});
|
2014
|
-
await onValid(fieldValues, e);
|
2015
|
-
}
|
2016
|
-
else {
|
2017
|
-
if (onInvalid) {
|
2018
|
-
await onInvalid({ ..._formState.errors }, e);
|
2019
|
-
}
|
2020
|
-
_focusError();
|
2021
|
-
}
|
1989
|
+
if (_options.resolver) {
|
1990
|
+
const { errors, values } = await _executeSchema();
|
1991
|
+
_formState.errors = errors;
|
1992
|
+
fieldValues = values;
|
2022
1993
|
}
|
2023
|
-
|
2024
|
-
|
2025
|
-
throw err;
|
1994
|
+
else {
|
1995
|
+
await executeBuiltInValidation(_fields);
|
2026
1996
|
}
|
2027
|
-
|
2028
|
-
_formState.isSubmitted = true;
|
1997
|
+
if (isEmptyObject(_formState.errors)) {
|
2029
1998
|
_subjects.state.next({
|
2030
|
-
|
2031
|
-
isSubmitting: false,
|
2032
|
-
isSubmitSuccessful: isEmptyObject(_formState.errors) && hasNoPromiseError,
|
2033
|
-
submitCount: _formState.submitCount + 1,
|
2034
|
-
errors: _formState.errors,
|
1999
|
+
errors: {},
|
2035
2000
|
});
|
2001
|
+
await onValid(fieldValues, e);
|
2002
|
+
}
|
2003
|
+
else {
|
2004
|
+
if (onInvalid) {
|
2005
|
+
await onInvalid({ ..._formState.errors }, e);
|
2006
|
+
}
|
2007
|
+
_focusError();
|
2036
2008
|
}
|
2009
|
+
_subjects.state.next({
|
2010
|
+
isSubmitted: true,
|
2011
|
+
isSubmitting: false,
|
2012
|
+
isSubmitSuccessful: isEmptyObject(_formState.errors),
|
2013
|
+
submitCount: _formState.submitCount + 1,
|
2014
|
+
errors: _formState.errors,
|
2015
|
+
});
|
2037
2016
|
};
|
2038
2017
|
const resetField = (name, options = {}) => {
|
2039
2018
|
if (get(_fields, name)) {
|