react-hook-form 7.41.3 → 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/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.mjs +41 -61
- 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/validateField.d.ts +2 -2
- package/dist/logic/validateField.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 +1 -1
- package/dist/types/path/eager.d.ts +40 -14
- package/dist/types/path/eager.d.ts.map +1 -1
- package/dist/types/utils.d.ts +15 -0
- 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) {
|
@@ -1789,7 +1780,7 @@ function createFormControl(props = {}, flushRootRender) {
|
|
1789
1780
|
isValid = isEmptyObject(errors);
|
1790
1781
|
}
|
1791
1782
|
else {
|
1792
|
-
error = (await validateField(field,
|
1783
|
+
error = (await validateField(field, _formValues, shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation))[name];
|
1793
1784
|
if (error) {
|
1794
1785
|
isValid = false;
|
1795
1786
|
}
|
@@ -1991,48 +1982,37 @@ function createFormControl(props = {}, flushRootRender) {
|
|
1991
1982
|
e.preventDefault && e.preventDefault();
|
1992
1983
|
e.persist && e.persist();
|
1993
1984
|
}
|
1994
|
-
let hasNoPromiseError = true;
|
1995
1985
|
let fieldValues = cloneObject(_formValues);
|
1996
1986
|
_subjects.state.next({
|
1997
1987
|
isSubmitting: true,
|
1998
1988
|
});
|
1999
|
-
|
2000
|
-
|
2001
|
-
|
2002
|
-
|
2003
|
-
fieldValues = values;
|
2004
|
-
}
|
2005
|
-
else {
|
2006
|
-
await executeBuiltInValidation(_fields);
|
2007
|
-
}
|
2008
|
-
if (isEmptyObject(_formState.errors)) {
|
2009
|
-
_subjects.state.next({
|
2010
|
-
errors: {},
|
2011
|
-
isSubmitting: true,
|
2012
|
-
});
|
2013
|
-
await onValid(fieldValues, e);
|
2014
|
-
}
|
2015
|
-
else {
|
2016
|
-
if (onInvalid) {
|
2017
|
-
await onInvalid({ ..._formState.errors }, e);
|
2018
|
-
}
|
2019
|
-
_focusError();
|
2020
|
-
}
|
1989
|
+
if (_options.resolver) {
|
1990
|
+
const { errors, values } = await _executeSchema();
|
1991
|
+
_formState.errors = errors;
|
1992
|
+
fieldValues = values;
|
2021
1993
|
}
|
2022
|
-
|
2023
|
-
|
2024
|
-
throw err;
|
1994
|
+
else {
|
1995
|
+
await executeBuiltInValidation(_fields);
|
2025
1996
|
}
|
2026
|
-
|
2027
|
-
_formState.isSubmitted = true;
|
1997
|
+
if (isEmptyObject(_formState.errors)) {
|
2028
1998
|
_subjects.state.next({
|
2029
|
-
|
2030
|
-
isSubmitting: false,
|
2031
|
-
isSubmitSuccessful: isEmptyObject(_formState.errors) && hasNoPromiseError,
|
2032
|
-
submitCount: _formState.submitCount + 1,
|
2033
|
-
errors: _formState.errors,
|
1999
|
+
errors: {},
|
2034
2000
|
});
|
2001
|
+
await onValid(fieldValues, e);
|
2002
|
+
}
|
2003
|
+
else {
|
2004
|
+
if (onInvalid) {
|
2005
|
+
await onInvalid({ ..._formState.errors }, e);
|
2006
|
+
}
|
2007
|
+
_focusError();
|
2035
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
|
+
});
|
2036
2016
|
};
|
2037
2017
|
const resetField = (name, options = {}) => {
|
2038
2018
|
if (get(_fields, name)) {
|