react-hook-form 7.76.0 → 7.76.1
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 +29 -34
- 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/{getFieldArrayParentNames.d.ts → isNameInFieldArray.d.ts} +2 -2
- package/dist/logic/isNameInFieldArray.d.ts.map +1 -0
- package/dist/logic/validateField.d.ts.map +1 -1
- package/dist/react-server.esm.mjs +29 -33
- package/dist/react-server.esm.mjs.map +1 -1
- package/dist/useController.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/logic/getFieldArrayParentNames.d.ts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createFormControl.d.ts","sourceRoot":"","sources":["../../src/logic/createFormControl.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"createFormControl.d.ts","sourceRoot":"","sources":["../../src/logic/createFormControl.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAcV,WAAW,EAiBX,YAAY,EAIZ,aAAa,EAYd,MAAM,UAAU,CAAC;AAuDlB,eAAO,MAAM,kBAAkB;;;;;;;;;;;;CAY9B,CAAC;AAEF,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,CAmtDA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { InternalFieldName } from '../types';
|
|
2
|
-
declare const _default: (names: Set<InternalFieldName>, name: InternalFieldName) =>
|
|
2
|
+
declare const _default: (names: Set<InternalFieldName>, name: InternalFieldName) => boolean;
|
|
3
3
|
export default _default;
|
|
4
|
-
//# sourceMappingURL=
|
|
4
|
+
//# sourceMappingURL=isNameInFieldArray.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isNameInFieldArray.d.ts","sourceRoot":"","sources":["../../src/logic/isNameInFieldArray.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;yBAElC,OAAO,GAAG,CAAC,iBAAiB,CAAC,EAAE,MAAM,iBAAiB;AAAtE,wBAMM"}
|
|
@@ -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;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,
|
|
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"}
|
|
@@ -376,16 +376,6 @@ var getEventValue = (event) => isObject(event) && event.target
|
|
|
376
376
|
: event.target.value
|
|
377
377
|
: event;
|
|
378
378
|
|
|
379
|
-
var getFieldArrayParentNames = (names, name) => {
|
|
380
|
-
const parts = name.split('.');
|
|
381
|
-
const matches = [];
|
|
382
|
-
let prefix = parts[0];
|
|
383
|
-
for (let i = 1; i < parts.length; prefix += '.' + parts[i++]) {
|
|
384
|
-
!isNaN(+parts[i]) && names.has(prefix) && matches.push(prefix);
|
|
385
|
-
}
|
|
386
|
-
return matches;
|
|
387
|
-
};
|
|
388
|
-
|
|
389
379
|
const defaultResult = {
|
|
390
380
|
value: false,
|
|
391
381
|
isValid: false,
|
|
@@ -506,6 +496,10 @@ var hasValidation = (options) => options.mount &&
|
|
|
506
496
|
options.pattern ||
|
|
507
497
|
options.validate);
|
|
508
498
|
|
|
499
|
+
var isNameInFieldArray = (names, name) => name
|
|
500
|
+
.split('.')
|
|
501
|
+
.some((part, index, arr) => !isNaN(Number(part)) && names.has(arr.slice(0, index).join('.')));
|
|
502
|
+
|
|
509
503
|
var isWatched = (name, _names, isBlurEvent) => !isBlurEvent &&
|
|
510
504
|
(_names.watchAll ||
|
|
511
505
|
_names.watch.has(name) ||
|
|
@@ -660,8 +654,7 @@ var validateField = async (field, disabledFieldNames, formValues, validateAllFie
|
|
|
660
654
|
isUndefined(inputValue)) ||
|
|
661
655
|
(isHTMLElement(ref) && ref.value === '') ||
|
|
662
656
|
inputValue === '' ||
|
|
663
|
-
(Array.isArray(inputValue) && !inputValue.length)
|
|
664
|
-
(valueAsNumber && typeof inputValue === 'number' && isNaN(inputValue));
|
|
657
|
+
(Array.isArray(inputValue) && !inputValue.length);
|
|
665
658
|
const appendErrorsCurry = appendErrors.bind(null, name, validateAllFieldCriteria, error);
|
|
666
659
|
const getMinMaxMessage = (exceedMax, maxLengthMessage, minLengthMessage, maxType = INPUT_VALIDATION_RULES.maxLength, minType = INPUT_VALIDATION_RULES.minLength) => {
|
|
667
660
|
const message = exceedMax ? maxLengthMessage : minLengthMessage;
|
|
@@ -1259,7 +1252,7 @@ function createFormControl(props = {}) {
|
|
|
1259
1252
|
: defaultValue),
|
|
1260
1253
|
}, isGlobal, defaultValue);
|
|
1261
1254
|
const _getFieldArray = (name) => compact(get(_state.mount ? _formValues : _defaultValues, name, _options.shouldUnregister ? get(_defaultValues, name, []) : []));
|
|
1262
|
-
const setFieldValue = (name, value, options = {}) => {
|
|
1255
|
+
const setFieldValue = (name, value, options = {}, skipClone = false) => {
|
|
1263
1256
|
const field = get(_fields, name);
|
|
1264
1257
|
let fieldValue = value;
|
|
1265
1258
|
if (field) {
|
|
@@ -1300,7 +1293,7 @@ function createFormControl(props = {}) {
|
|
|
1300
1293
|
if (!fieldReference.ref.type) {
|
|
1301
1294
|
_subjects.state.next({
|
|
1302
1295
|
name,
|
|
1303
|
-
values: cloneObject(_formValues),
|
|
1296
|
+
values: skipClone ? _formValues : cloneObject(_formValues),
|
|
1304
1297
|
});
|
|
1305
1298
|
}
|
|
1306
1299
|
}
|
|
@@ -1310,7 +1303,7 @@ function createFormControl(props = {}) {
|
|
|
1310
1303
|
updateTouchAndDirty(name, fieldValue, options.shouldTouch, options.shouldDirty, true);
|
|
1311
1304
|
options.shouldValidate && trigger(name);
|
|
1312
1305
|
};
|
|
1313
|
-
const setFieldValues = (name, value, options) => {
|
|
1306
|
+
const setFieldValues = (name, value, options, skipClone = false) => {
|
|
1314
1307
|
for (const fieldKey in value) {
|
|
1315
1308
|
if (!value.hasOwnProperty(fieldKey)) {
|
|
1316
1309
|
return;
|
|
@@ -1322,14 +1315,14 @@ function createFormControl(props = {}) {
|
|
|
1322
1315
|
isObject(fieldValue) ||
|
|
1323
1316
|
(field && !field._f)) &&
|
|
1324
1317
|
!isDateObject(fieldValue)
|
|
1325
|
-
? setFieldValues(fieldName, fieldValue, options)
|
|
1326
|
-
: setFieldValue(fieldName, fieldValue, options);
|
|
1318
|
+
? setFieldValues(fieldName, fieldValue, options, skipClone)
|
|
1319
|
+
: setFieldValue(fieldName, fieldValue, options, skipClone);
|
|
1327
1320
|
}
|
|
1328
1321
|
};
|
|
1329
|
-
const
|
|
1322
|
+
const _setValue = (name, value, options, skipClone) => {
|
|
1330
1323
|
const field = get(_fields, name);
|
|
1331
1324
|
const isFieldArray = _names.array.has(name);
|
|
1332
|
-
const cloneValue = cloneObject(value);
|
|
1325
|
+
const cloneValue = skipClone ? value : cloneObject(value);
|
|
1333
1326
|
const previousValue = get(_formValues, name);
|
|
1334
1327
|
const isValueUnchanged = deepEqual(previousValue, cloneValue);
|
|
1335
1328
|
if (!isValueUnchanged) {
|
|
@@ -1338,7 +1331,7 @@ function createFormControl(props = {}) {
|
|
|
1338
1331
|
if (isFieldArray) {
|
|
1339
1332
|
_subjects.array.next({
|
|
1340
1333
|
name,
|
|
1341
|
-
values: cloneObject(_formValues),
|
|
1334
|
+
values: skipClone ? _formValues : cloneObject(_formValues),
|
|
1342
1335
|
});
|
|
1343
1336
|
if ((_proxyFormState.isDirty ||
|
|
1344
1337
|
_proxyFormState.dirtyFields ||
|
|
@@ -1357,20 +1350,15 @@ function createFormControl(props = {}) {
|
|
|
1357
1350
|
const isEmpty = (Array.isArray(cloneValue) && !cloneValue.length) ||
|
|
1358
1351
|
isEmptyObject(cloneValue);
|
|
1359
1352
|
if (!field || field._f || isNullOrUndefined(cloneValue) || isEmpty) {
|
|
1360
|
-
setFieldValue(name, cloneValue, options);
|
|
1353
|
+
setFieldValue(name, cloneValue, options, skipClone);
|
|
1361
1354
|
}
|
|
1362
1355
|
else {
|
|
1363
|
-
setFieldValues(name, cloneValue, options);
|
|
1356
|
+
setFieldValues(name, cloneValue, options, skipClone);
|
|
1364
1357
|
}
|
|
1365
1358
|
}
|
|
1366
1359
|
if (!isValueUnchanged) {
|
|
1367
1360
|
const watched = isWatched(name, _names);
|
|
1368
|
-
const values = cloneObject(_formValues);
|
|
1369
|
-
if (!isFieldArray) {
|
|
1370
|
-
for (const arrayName of getFieldArrayParentNames(_names.array, name)) {
|
|
1371
|
-
_subjects.array.next({ name: arrayName, values });
|
|
1372
|
-
}
|
|
1373
|
-
}
|
|
1361
|
+
const values = skipClone ? _formValues : cloneObject(_formValues);
|
|
1374
1362
|
_subjects.state.next({
|
|
1375
1363
|
...(watched && _formState),
|
|
1376
1364
|
name: _state.mount || watched ? name : undefined,
|
|
@@ -1378,7 +1366,8 @@ function createFormControl(props = {}) {
|
|
|
1378
1366
|
});
|
|
1379
1367
|
}
|
|
1380
1368
|
};
|
|
1381
|
-
const
|
|
1369
|
+
const setValue = (name, value, options = {}) => _setValue(name, value, options, false);
|
|
1370
|
+
const setValues = (formValues, options = {}) => {
|
|
1382
1371
|
const updatedFormValues = isFunction(formValues)
|
|
1383
1372
|
? formValues(_formValues)
|
|
1384
1373
|
: formValues;
|
|
@@ -1388,9 +1377,17 @@ function createFormControl(props = {}) {
|
|
|
1388
1377
|
...updatedFormValues,
|
|
1389
1378
|
};
|
|
1390
1379
|
for (const fieldName of _names.mount) {
|
|
1391
|
-
|
|
1380
|
+
_setValue(fieldName, get(updatedFormValues, fieldName), options, true);
|
|
1381
|
+
}
|
|
1382
|
+
_subjects.state.next({
|
|
1383
|
+
..._formState,
|
|
1384
|
+
name: undefined,
|
|
1385
|
+
type: undefined,
|
|
1386
|
+
values: _formValues,
|
|
1387
|
+
});
|
|
1388
|
+
if (options.shouldValidate) {
|
|
1389
|
+
_setValid();
|
|
1392
1390
|
}
|
|
1393
|
-
_subjects.state.next({ ..._formState, values: _formValues });
|
|
1394
1391
|
}
|
|
1395
1392
|
};
|
|
1396
1393
|
const onChange = async (event) => {
|
|
@@ -1760,8 +1757,7 @@ function createFormControl(props = {}) {
|
|
|
1760
1757
|
field._f.mount = false;
|
|
1761
1758
|
}
|
|
1762
1759
|
(_options.shouldUnregister || options.shouldUnregister) &&
|
|
1763
|
-
!(
|
|
1764
|
-
_state.action) &&
|
|
1760
|
+
!(isNameInFieldArray(_names.array, name) && _state.action) &&
|
|
1765
1761
|
_names.unMount.add(name);
|
|
1766
1762
|
}
|
|
1767
1763
|
},
|