react-hook-form 7.62.0 → 7.63.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 +60 -38
- 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/getDirtyFields.d.ts +3 -2
- package/dist/logic/getDirtyFields.d.ts.map +1 -1
- package/dist/logic/validateField.d.ts.map +1 -1
- package/dist/react-server.esm.mjs +54 -38
- package/dist/react-server.esm.mjs.map +1 -1
- package/dist/types/form.d.ts +14 -3
- package/dist/types/form.d.ts.map +1 -1
- package/dist/types/resolvers.d.ts +2 -2
- package/dist/types/resolvers.d.ts.map +1 -1
- package/dist/useController.d.ts.map +1 -1
- package/dist/utils/extractFormValues.d.ts +2 -0
- package/dist/utils/extractFormValues.d.ts.map +1 -0
- package/package.json +33 -35
- package/dist/utils/isMessage.d.ts +0 -4
- package/dist/utils/isMessage.d.ts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createFormControl.d.ts","sourceRoot":"","sources":["../../src/logic/createFormControl.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAaV,WAAW,
|
|
1
|
+
{"version":3,"file":"createFormControl.d.ts","sourceRoot":"","sources":["../../src/logic/createFormControl.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAaV,WAAW,EAiBX,YAAY,EAIZ,aAAa,EAUd,MAAM,UAAU,CAAC;AAqDlB,wBAAgB,iBAAiB,CAC/B,YAAY,SAAS,WAAW,GAAG,WAAW,EAC9C,QAAQ,GAAG,GAAG,EACd,kBAAkB,GAAG,YAAY,EAEjC,KAAK,GAAE,YAAY,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,CAAM,GACnE,IAAI,CACL,aAAa,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,CAAC,EACzD,WAAW,CACZ,GAAG;IACF,WAAW,EAAE,IAAI,CACf,aAAa,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,CAAC,EACzD,WAAW,CACZ,CAAC;CACH,CA07CA"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
declare
|
|
2
|
-
export default
|
|
1
|
+
declare function markFieldsDirty<T>(data: T, fields?: Record<string, any>): Record<string, any>;
|
|
2
|
+
export default function getDirtyFields<T>(data: T, formValues: T, dirtyFieldsFromValues?: Record<Extract<keyof T, string>, ReturnType<typeof markFieldsDirty> | boolean>): Record<Extract<keyof T, string>, boolean | Record<string, any>>;
|
|
3
|
+
export {};
|
|
3
4
|
//# sourceMappingURL=getDirtyFields.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDirtyFields.d.ts","sourceRoot":"","sources":["../../src/logic/getDirtyFields.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getDirtyFields.d.ts","sourceRoot":"","sources":["../../src/logic/getDirtyFields.ts"],"names":[],"mappings":"AAWA,iBAAS,eAAe,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,uBAWpE;AAED,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,CAAC,EACtC,IAAI,EAAE,CAAC,EACP,UAAU,EAAE,CAAC,EACb,qBAAqB,CAAC,EAAE,MAAM,CAC5B,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,EACxB,UAAU,CAAC,OAAO,eAAe,CAAC,GAAG,OAAO,CAC7C,mEA0BF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validateField.d.ts","sourceRoot":"","sources":["../../src/logic/validateField.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,KAAK,EAEL,WAAW,EACX,mBAAmB,EACnB,eAAe,EAKhB,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"validateField.d.ts","sourceRoot":"","sources":["../../src/logic/validateField.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,KAAK,EAEL,WAAW,EACX,mBAAmB,EACnB,eAAe,EAKhB,MAAM,UAAU,CAAC;yBAqBI,CAAC,SAAS,WAAW,EACzC,OAAO,KAAK,EACZ,oBAAoB,eAAe,EACnC,YAAY,CAAC,EACb,0BAA0B,OAAO,EACjC,4BAA4B,OAAO,EACnC,eAAe,OAAO,KACrB,OAAO,CAAC,mBAAmB,CAAC;AAP/B,wBA6PE"}
|
|
@@ -144,6 +144,26 @@ function deepEqual(object1, object2, _internal_visited = new WeakSet()) {
|
|
|
144
144
|
return true;
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
+
function extractFormValues(fieldsState, formValues) {
|
|
148
|
+
const values = {};
|
|
149
|
+
for (const key in fieldsState) {
|
|
150
|
+
if (fieldsState.hasOwnProperty(key)) {
|
|
151
|
+
const fieldState = fieldsState[key];
|
|
152
|
+
const fieldValue = formValues[key];
|
|
153
|
+
if (fieldState && isObject(fieldState) && fieldValue) {
|
|
154
|
+
const nestedFieldsState = extractFormValues(fieldState, fieldValue);
|
|
155
|
+
if (isObject(nestedFieldsState)) {
|
|
156
|
+
values[key] = nestedFieldsState;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
else if (fieldsState[key]) {
|
|
160
|
+
values[key] = fieldValue;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return values;
|
|
165
|
+
}
|
|
166
|
+
|
|
147
167
|
var isKey = (value) => /^\w*$/.test(value);
|
|
148
168
|
|
|
149
169
|
var isUndefined = (val) => val === undefined;
|
|
@@ -274,46 +294,40 @@ var objectHasFunction = (data) => {
|
|
|
274
294
|
return false;
|
|
275
295
|
};
|
|
276
296
|
|
|
297
|
+
function isTraversable(value) {
|
|
298
|
+
return Array.isArray(value) || (isObject(value) && !objectHasFunction(value));
|
|
299
|
+
}
|
|
277
300
|
function markFieldsDirty(data, fields = {}) {
|
|
278
|
-
const
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
}
|
|
286
|
-
else if (!isNullOrUndefined(data[key])) {
|
|
287
|
-
fields[key] = true;
|
|
288
|
-
}
|
|
301
|
+
for (const key in data) {
|
|
302
|
+
if (isTraversable(data[key])) {
|
|
303
|
+
fields[key] = Array.isArray(data[key]) ? [] : {};
|
|
304
|
+
markFieldsDirty(data[key], fields[key]);
|
|
305
|
+
}
|
|
306
|
+
else if (!isNullOrUndefined(data[key])) {
|
|
307
|
+
fields[key] = true;
|
|
289
308
|
}
|
|
290
309
|
}
|
|
291
310
|
return fields;
|
|
292
311
|
}
|
|
293
|
-
function
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
dirtyFieldsFromValues[key] = Array.isArray(data[key])
|
|
302
|
-
? markFieldsDirty(data[key], [])
|
|
303
|
-
: { ...markFieldsDirty(data[key]) };
|
|
304
|
-
}
|
|
305
|
-
else {
|
|
306
|
-
getDirtyFieldsFromDefaultValues(data[key], isNullOrUndefined(formValues) ? {} : formValues[key], dirtyFieldsFromValues[key]);
|
|
307
|
-
}
|
|
312
|
+
function getDirtyFields(data, formValues, dirtyFieldsFromValues) {
|
|
313
|
+
if (!dirtyFieldsFromValues) {
|
|
314
|
+
dirtyFieldsFromValues = markFieldsDirty(formValues);
|
|
315
|
+
}
|
|
316
|
+
for (const key in data) {
|
|
317
|
+
if (isTraversable(data[key])) {
|
|
318
|
+
if (isUndefined(formValues) || isPrimitive(dirtyFieldsFromValues[key])) {
|
|
319
|
+
dirtyFieldsFromValues[key] = markFieldsDirty(data[key], Array.isArray(data[key]) ? [] : {});
|
|
308
320
|
}
|
|
309
321
|
else {
|
|
310
|
-
|
|
322
|
+
getDirtyFields(data[key], isNullOrUndefined(formValues) ? {} : formValues[key], dirtyFieldsFromValues[key]);
|
|
311
323
|
}
|
|
312
324
|
}
|
|
325
|
+
else {
|
|
326
|
+
dirtyFieldsFromValues[key] = !deepEqual(data[key], formValues[key]);
|
|
327
|
+
}
|
|
313
328
|
}
|
|
314
329
|
return dirtyFieldsFromValues;
|
|
315
330
|
}
|
|
316
|
-
var getDirtyFields = (defaultValues, formValues) => getDirtyFieldsFromDefaultValues(defaultValues, formValues, markFieldsDirty(formValues));
|
|
317
331
|
|
|
318
332
|
var getEventValue = (event) => isObject(event) && event.target
|
|
319
333
|
? isCheckBoxInput(event.target)
|
|
@@ -557,15 +571,13 @@ var updateFieldArrayRootError = (errors, error, name) => {
|
|
|
557
571
|
return errors;
|
|
558
572
|
};
|
|
559
573
|
|
|
560
|
-
var isMessage = (value) => isString(value);
|
|
561
|
-
|
|
562
574
|
function getValidateError(result, ref, type = 'validate') {
|
|
563
|
-
if (
|
|
564
|
-
(Array.isArray(result) && result.every(
|
|
575
|
+
if (isString(result) ||
|
|
576
|
+
(Array.isArray(result) && result.every(isString)) ||
|
|
565
577
|
(isBoolean(result) && !result)) {
|
|
566
578
|
return {
|
|
567
579
|
type,
|
|
568
|
-
message:
|
|
580
|
+
message: isString(result) ? result : '',
|
|
569
581
|
ref,
|
|
570
582
|
};
|
|
571
583
|
}
|
|
@@ -618,7 +630,7 @@ var validateField = async (field, disabledFieldNames, formValues, validateAllFie
|
|
|
618
630
|
(isBoolean(inputValue) && !inputValue) ||
|
|
619
631
|
(isCheckBox && !getCheckboxValue(refs).isValid) ||
|
|
620
632
|
(isRadio && !getRadioValue(refs).isValid))) {
|
|
621
|
-
const { value, message } =
|
|
633
|
+
const { value, message } = isString(required)
|
|
622
634
|
? { value: !!required, message: required }
|
|
623
635
|
: getValueAndMessage(required);
|
|
624
636
|
if (value) {
|
|
@@ -1024,11 +1036,11 @@ function createFormControl(props = {}) {
|
|
|
1024
1036
|
const isFieldArrayRoot = _names.array.has(_f.name);
|
|
1025
1037
|
const isPromiseFunction = field._f && hasPromiseValidation(field._f);
|
|
1026
1038
|
if (isPromiseFunction && _proxyFormState.validatingFields) {
|
|
1027
|
-
_updateIsValidating([name], true);
|
|
1039
|
+
_updateIsValidating([_f.name], true);
|
|
1028
1040
|
}
|
|
1029
1041
|
const fieldError = await validateField(field, _names.disabled, _formValues, shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation && !shouldOnlyCheckValid, isFieldArrayRoot);
|
|
1030
1042
|
if (isPromiseFunction && _proxyFormState.validatingFields) {
|
|
1031
|
-
_updateIsValidating([name]);
|
|
1043
|
+
_updateIsValidating([_f.name]);
|
|
1032
1044
|
}
|
|
1033
1045
|
if (fieldError[_f.name]) {
|
|
1034
1046
|
context.valid = false;
|
|
@@ -1261,6 +1273,7 @@ function createFormControl(props = {}) {
|
|
|
1261
1273
|
}
|
|
1262
1274
|
if (isFieldValueUpdated) {
|
|
1263
1275
|
field._f.deps &&
|
|
1276
|
+
(!Array.isArray(field._f.deps) || field._f.deps.length > 0) &&
|
|
1264
1277
|
trigger(field._f.deps);
|
|
1265
1278
|
shouldRenderByError(name, isValid, error, fieldState);
|
|
1266
1279
|
}
|
|
@@ -1308,10 +1321,13 @@ function createFormControl(props = {}) {
|
|
|
1308
1321
|
iterateFieldsByAction(_fields, _focusInput, name ? fieldNames : _names.mount);
|
|
1309
1322
|
return validationResult;
|
|
1310
1323
|
};
|
|
1311
|
-
const getValues = (fieldNames) => {
|
|
1312
|
-
|
|
1324
|
+
const getValues = (fieldNames, config) => {
|
|
1325
|
+
let values = {
|
|
1313
1326
|
...(_state.mount ? _formValues : _defaultValues),
|
|
1314
1327
|
};
|
|
1328
|
+
if (config) {
|
|
1329
|
+
values = extractFormValues(config.dirtyFields ? _formState.dirtyFields : _formState.touchedFields, values);
|
|
1330
|
+
}
|
|
1315
1331
|
return isUndefined(fieldNames)
|
|
1316
1332
|
? values
|
|
1317
1333
|
: isString(fieldNames)
|