react-hook-form 6.9.4 → 6.9.5
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 +29 -30
- 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 +29 -30
- package/dist/index.esm.js.map +1 -1
- package/dist/index.ie11.development.js +51 -52
- package/dist/index.ie11.development.js.map +1 -1
- package/dist/index.ie11.production.min.js +1 -1
- package/dist/index.ie11.production.min.js.map +1 -1
- package/dist/index.umd.development.js +29 -30
- 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/dist/types/form.d.ts +1 -3
- package/package.json +1 -1
@@ -836,13 +836,14 @@ function useForm({ mode = VALIDATION_MODE.onSubmit, reValidateMode = VALIDATION_
|
|
836
836
|
}
|
837
837
|
else if (!isPrimitive(value)) {
|
838
838
|
setInternalValues(name, value, config);
|
839
|
-
if (fieldArrayNamesRef.current.has(name)
|
839
|
+
if (fieldArrayNamesRef.current.has(name)) {
|
840
840
|
fieldArrayDefaultValuesRef.current[name] = value;
|
841
841
|
resetFieldArrayFunctionRef.current[name]({
|
842
842
|
[name]: value,
|
843
843
|
});
|
844
|
-
if (readFormStateRef.current.isDirty ||
|
845
|
-
readFormStateRef.current.dirtyFields)
|
844
|
+
if ((readFormStateRef.current.isDirty ||
|
845
|
+
readFormStateRef.current.dirtyFields) &&
|
846
|
+
config.shouldDirty) {
|
846
847
|
set(formStateRef.current.dirtyFields, name, setFieldArrayDirtyFields(value, get(defaultValuesRef.current, name, []), get(formStateRef.current.dirtyFields, name, [])));
|
847
848
|
updateFormState({
|
848
849
|
isDirty: !deepEqual(Object.assign(Object.assign({}, getValues()), { [name]: value }), defaultValuesRef.current),
|
@@ -952,6 +953,22 @@ function useForm({ mode = VALIDATION_MODE.onSubmit, reValidateMode = VALIDATION_
|
|
952
953
|
});
|
953
954
|
}, [isValidateAllFieldCriteria]);
|
954
955
|
const removeFieldEventListener = React.useCallback((field, forceDelete) => findRemovedFieldAndRemoveListener(fieldsRef, handleChangeRef.current, field, shallowFieldsStateRef, shouldUnregister, forceDelete), [shouldUnregister]);
|
956
|
+
const updateWatchedValue = (name) => {
|
957
|
+
if (isWatchAllRef.current) {
|
958
|
+
updateFormState();
|
959
|
+
}
|
960
|
+
else if (watchFieldsRef) {
|
961
|
+
let shouldRenderUseWatch = true;
|
962
|
+
for (const watchField of watchFieldsRef.current) {
|
963
|
+
if (watchField.startsWith(name)) {
|
964
|
+
updateFormState();
|
965
|
+
shouldRenderUseWatch = false;
|
966
|
+
break;
|
967
|
+
}
|
968
|
+
}
|
969
|
+
shouldRenderUseWatch && renderWatchedInputs(name);
|
970
|
+
}
|
971
|
+
};
|
955
972
|
const removeFieldEventListenerAndRef = React.useCallback((field, forceDelete) => {
|
956
973
|
if (field) {
|
957
974
|
removeFieldEventListener(field, forceDelete);
|
@@ -967,6 +984,7 @@ function useForm({ mode = VALIDATION_MODE.onSubmit, reValidateMode = VALIDATION_
|
|
967
984
|
dirtyFields: formStateRef.current.dirtyFields,
|
968
985
|
});
|
969
986
|
resolverRef.current && validateResolver();
|
987
|
+
updateWatchedValue(field.ref.name);
|
970
988
|
}
|
971
989
|
}
|
972
990
|
}, [validateResolver, removeFieldEventListener]);
|
@@ -1122,16 +1140,14 @@ function useForm({ mode = VALIDATION_MODE.onSubmit, reValidateMode = VALIDATION_
|
|
1122
1140
|
}
|
1123
1141
|
let fieldErrors = {};
|
1124
1142
|
let fieldValues = setFieldArrayDefaultValues(getFieldsValues(fieldsRef, shallowFieldsStateRef, true));
|
1125
|
-
|
1143
|
+
readFormStateRef.current.isSubmitting &&
|
1126
1144
|
updateFormState({
|
1127
1145
|
isSubmitting: true,
|
1128
1146
|
});
|
1129
|
-
}
|
1130
1147
|
try {
|
1131
1148
|
if (resolverRef.current) {
|
1132
1149
|
const { errors, values } = await resolverRef.current(fieldValues, contextRef.current, isValidateAllFieldCriteria);
|
1133
|
-
formStateRef.current.errors = errors;
|
1134
|
-
fieldErrors = errors;
|
1150
|
+
formStateRef.current.errors = fieldErrors = errors;
|
1135
1151
|
fieldValues = values;
|
1136
1152
|
}
|
1137
1153
|
else {
|
@@ -1215,13 +1231,11 @@ function useForm({ mode = VALIDATION_MODE.onSubmit, reValidateMode = VALIDATION_
|
|
1215
1231
|
}
|
1216
1232
|
fieldsRef.current = {};
|
1217
1233
|
defaultValuesRef.current = cloneObject(values || defaultValuesRef.current);
|
1218
|
-
|
1219
|
-
|
1220
|
-
}
|
1234
|
+
values && renderWatchedInputs('');
|
1235
|
+
Object.values(resetFieldArrayFunctionRef.current).forEach((resetFieldArray) => isFunction(resetFieldArray) && resetFieldArray());
|
1221
1236
|
shallowFieldsStateRef.current = shouldUnregister
|
1222
1237
|
? {}
|
1223
1238
|
: cloneObject(values) || {};
|
1224
|
-
Object.values(resetFieldArrayFunctionRef.current).forEach((resetFieldArray) => isFunction(resetFieldArray) && resetFieldArray());
|
1225
1239
|
resetRefs(omitResetState);
|
1226
1240
|
};
|
1227
1241
|
React.useEffect(() => {
|
@@ -1252,15 +1266,13 @@ function useForm({ mode = VALIDATION_MODE.onSubmit, reValidateMode = VALIDATION_
|
|
1252
1266
|
register: React.useCallback(register, [defaultValuesRef.current]),
|
1253
1267
|
unregister: React.useCallback(unregister, []),
|
1254
1268
|
};
|
1255
|
-
const control = Object.assign({
|
1269
|
+
const control = Object.assign({ updateWatchedValue,
|
1256
1270
|
shouldUnregister,
|
1257
1271
|
removeFieldEventListener,
|
1258
1272
|
watchInternal, mode: modeRef.current, reValidateMode: {
|
1259
1273
|
isReValidateOnBlur,
|
1260
1274
|
isReValidateOnChange,
|
1261
1275
|
}, fieldsRef,
|
1262
|
-
isWatchAllRef,
|
1263
|
-
watchFieldsRef,
|
1264
1276
|
resetFieldArrayFunctionRef,
|
1265
1277
|
useWatchFieldsRef,
|
1266
1278
|
useWatchRenderFunctionsRef,
|
@@ -1408,7 +1420,7 @@ const useFieldArray = ({ control, name, keyName = 'id', }) => {
|
|
1408
1420
|
}
|
1409
1421
|
}
|
1410
1422
|
const focusIndexRef = React.useRef(-1);
|
1411
|
-
const {
|
1423
|
+
const { updateWatchedValue, resetFieldArrayFunctionRef, fieldArrayNamesRef, fieldsRef, defaultValuesRef, removeFieldEventListener, formStateRef, shallowFieldsStateRef, updateFormState, readFormStateRef, validFieldsRef, fieldsWithValidationRef, fieldArrayDefaultValuesRef, validateResolver, getValues, shouldUnregister, } = control || methods.control;
|
1412
1424
|
const fieldArrayParentName = getFieldArrayParentName(name);
|
1413
1425
|
const memoizedDefaultValues = React.useRef([
|
1414
1426
|
...(get(fieldArrayDefaultValuesRef.current, fieldArrayParentName)
|
@@ -1608,20 +1620,7 @@ const useFieldArray = ({ control, name, keyName = 'id', }) => {
|
|
1608
1620
|
defaultValues.pop();
|
1609
1621
|
set(fieldArrayDefaultValuesRef.current, name, defaultValues);
|
1610
1622
|
}
|
1611
|
-
|
1612
|
-
updateFormState();
|
1613
|
-
}
|
1614
|
-
else if (watchFieldsRef) {
|
1615
|
-
let shouldRenderUseWatch = true;
|
1616
|
-
for (const watchField of watchFieldsRef.current) {
|
1617
|
-
if (watchField.startsWith(name)) {
|
1618
|
-
updateFormState();
|
1619
|
-
shouldRenderUseWatch = false;
|
1620
|
-
break;
|
1621
|
-
}
|
1622
|
-
}
|
1623
|
-
shouldRenderUseWatch && renderWatchedInputs(name);
|
1624
|
-
}
|
1623
|
+
updateWatchedValue(name);
|
1625
1624
|
if (focusIndexRef.current > -1) {
|
1626
1625
|
for (const key in fieldsRef.current) {
|
1627
1626
|
const field = fieldsRef.current[key];
|
@@ -1673,7 +1672,7 @@ function useWatch({ control, name, defaultValue, }) {
|
|
1673
1672
|
: defaultValuesRef.current
|
1674
1673
|
: defaultValue);
|
1675
1674
|
const idRef = React.useRef();
|
1676
|
-
const defaultValueRef = React.useRef(
|
1675
|
+
const defaultValueRef = React.useRef(defaultValue);
|
1677
1676
|
const updateWatchValue = React.useCallback(() => {
|
1678
1677
|
const value = watchInternal(name, defaultValueRef.current, idRef.current);
|
1679
1678
|
setValue(isObject(value)
|