@bombillazo/rhf-plus 7.60.1-plus.0 → 7.62.0-plus.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/README.md +22 -5
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.mjs +91 -21
- 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/react-server.esm.mjs +64 -10
- package/dist/react-server.esm.mjs.map +1 -1
- package/dist/types/form.d.ts +2 -2
- package/dist/types/form.d.ts.map +1 -1
- package/dist/types/utils.d.ts +1 -1
- package/dist/types/utils.d.ts.map +1 -1
- package/dist/useController.d.ts.map +1 -1
- package/dist/useForm.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createFormControl.d.ts","sourceRoot":"","sources":["../../src/logic/createFormControl.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAaV,WAAW,EACX,YAAY,EAgBZ,YAAY,EAIZ,aAAa,EAUd,MAAM,UAAU,CAAC;AAuDlB,wBAAgB,iBAAiB,CAC/B,YAAY,SAAS,WAAW,GAAG,WAAW,EAC9C,QAAQ,GAAG,GAAG,EACd,kBAAkB,GAAG,YAAY,EACjC,SAAS,SAAS,YAAY,GAAG,GAAG,EAEpC,KAAK,GAAE,YAAY,CACjB,YAAY,EACZ,QAAQ,EACR,kBAAkB,EAClB,SAAS,CACL,GACL,IAAI,CACL,aAAa,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,EAAE,SAAS,CAAC,EACpE,WAAW,CACZ,GAAG;IACF,WAAW,EAAE,IAAI,CACf,aAAa,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,EAAE,SAAS,CAAC,EACpE,WAAW,CACZ,CAAC;CACH,
|
|
1
|
+
{"version":3,"file":"createFormControl.d.ts","sourceRoot":"","sources":["../../src/logic/createFormControl.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAaV,WAAW,EACX,YAAY,EAgBZ,YAAY,EAIZ,aAAa,EAUd,MAAM,UAAU,CAAC;AAuDlB,wBAAgB,iBAAiB,CAC/B,YAAY,SAAS,WAAW,GAAG,WAAW,EAC9C,QAAQ,GAAG,GAAG,EACd,kBAAkB,GAAG,YAAY,EACjC,SAAS,SAAS,YAAY,GAAG,GAAG,EAEpC,KAAK,GAAE,YAAY,CACjB,YAAY,EACZ,QAAQ,EACR,kBAAkB,EAClB,SAAS,CACL,GACL,IAAI,CACL,aAAa,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,EAAE,SAAS,CAAC,EACpE,WAAW,CACZ,GAAG;IACF,WAAW,EAAE,IAAI,CACf,aAAa,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,EAAE,SAAS,CAAC,EACpE,WAAW,CACZ,CAAC;CACH,CAoiDA"}
|
|
@@ -58,7 +58,7 @@ function cloneObject(data) {
|
|
|
58
58
|
}
|
|
59
59
|
else if (!(isWeb && (data instanceof Blob || isFileListInstance)) &&
|
|
60
60
|
(isArray || isObject(data))) {
|
|
61
|
-
copy = isArray ? [] :
|
|
61
|
+
copy = isArray ? [] : Object.create(Object.getPrototypeOf(data));
|
|
62
62
|
if (!isArray && !isPlainObject(data)) {
|
|
63
63
|
copy = data;
|
|
64
64
|
}
|
|
@@ -826,7 +826,9 @@ function createFormControl(props = {}) {
|
|
|
826
826
|
dirtyFields: {},
|
|
827
827
|
validatingFields: {},
|
|
828
828
|
errors: _options.errors || {},
|
|
829
|
-
disabled: _options.disabled
|
|
829
|
+
disabled: Array.isArray(_options.disabled)
|
|
830
|
+
? false
|
|
831
|
+
: _options.disabled || false,
|
|
830
832
|
metadata: _options.defaultMetadata || {},
|
|
831
833
|
};
|
|
832
834
|
let _fields = {};
|
|
@@ -873,7 +875,7 @@ function createFormControl(props = {}) {
|
|
|
873
875
|
timer = setTimeout(callback, wait);
|
|
874
876
|
};
|
|
875
877
|
const _setValid = async (shouldUpdateValid) => {
|
|
876
|
-
if (!_options.disabled &&
|
|
878
|
+
if ((Array.isArray(_options.disabled) || !_options.disabled) &&
|
|
877
879
|
(_proxyFormState.isValid ||
|
|
878
880
|
_proxySubscribeFormState.isValid ||
|
|
879
881
|
shouldUpdateValid)) {
|
|
@@ -1235,6 +1237,22 @@ function createFormControl(props = {}) {
|
|
|
1235
1237
|
const validationModeBeforeSubmit = getValidationModes(_options.mode);
|
|
1236
1238
|
const validationModeAfterSubmit = getValidationModes(_options.reValidateMode);
|
|
1237
1239
|
if (field) {
|
|
1240
|
+
// Check if field is disabled and should not process events
|
|
1241
|
+
const isFieldDisabled = isBoolean(field._f.disabled)
|
|
1242
|
+
? field._f.disabled
|
|
1243
|
+
: isBoolean(_options.disabled)
|
|
1244
|
+
? _options.disabled
|
|
1245
|
+
: Array.isArray(_options.disabled)
|
|
1246
|
+
? new Set(_options.disabled).has(name)
|
|
1247
|
+
: false;
|
|
1248
|
+
if (isFieldDisabled) {
|
|
1249
|
+
// Restore the original value if the field is disabled
|
|
1250
|
+
const originalValue = get(_formValues, name);
|
|
1251
|
+
if (target.value !== originalValue) {
|
|
1252
|
+
target.value = originalValue;
|
|
1253
|
+
}
|
|
1254
|
+
return;
|
|
1255
|
+
}
|
|
1238
1256
|
let error;
|
|
1239
1257
|
let isValid;
|
|
1240
1258
|
const fieldValue = target.type
|
|
@@ -1249,8 +1267,10 @@ function createFormControl(props = {}) {
|
|
|
1249
1267
|
const watched = isWatched(name, _names, isBlurEvent);
|
|
1250
1268
|
set(_formValues, name, fieldValue);
|
|
1251
1269
|
if (isBlurEvent) {
|
|
1252
|
-
|
|
1253
|
-
|
|
1270
|
+
if (!target || !target.readOnly) {
|
|
1271
|
+
field._f.onBlur && field._f.onBlur(event);
|
|
1272
|
+
delayErrorCallback && delayErrorCallback(0);
|
|
1273
|
+
}
|
|
1254
1274
|
}
|
|
1255
1275
|
else if (field._f.onChange) {
|
|
1256
1276
|
field._f.onChange(event);
|
|
@@ -1459,7 +1479,9 @@ function createFormControl(props = {}) {
|
|
|
1459
1479
|
};
|
|
1460
1480
|
const register = (name, options = {}) => {
|
|
1461
1481
|
let field = get(_fields, name);
|
|
1462
|
-
const disabledIsDefined = isBoolean(options.disabled) ||
|
|
1482
|
+
const disabledIsDefined = isBoolean(options.disabled) ||
|
|
1483
|
+
isBoolean(_options.disabled) ||
|
|
1484
|
+
Array.isArray(_options.disabled);
|
|
1463
1485
|
set(_fields, name, {
|
|
1464
1486
|
...(field || {}),
|
|
1465
1487
|
_f: {
|
|
@@ -1474,7 +1496,9 @@ function createFormControl(props = {}) {
|
|
|
1474
1496
|
_setDisabledField({
|
|
1475
1497
|
disabled: isBoolean(options.disabled)
|
|
1476
1498
|
? options.disabled
|
|
1477
|
-
: _options.disabled
|
|
1499
|
+
: Array.isArray(_options.disabled)
|
|
1500
|
+
? new Set(_options.disabled).has(name)
|
|
1501
|
+
: _options.disabled,
|
|
1478
1502
|
name,
|
|
1479
1503
|
});
|
|
1480
1504
|
}
|
|
@@ -1483,7 +1507,13 @@ function createFormControl(props = {}) {
|
|
|
1483
1507
|
}
|
|
1484
1508
|
return {
|
|
1485
1509
|
...(disabledIsDefined
|
|
1486
|
-
? {
|
|
1510
|
+
? {
|
|
1511
|
+
disabled: isBoolean(options.disabled)
|
|
1512
|
+
? options.disabled
|
|
1513
|
+
: Array.isArray(_options.disabled)
|
|
1514
|
+
? new Set(_options.disabled).has(name)
|
|
1515
|
+
: !!_options.disabled,
|
|
1516
|
+
}
|
|
1487
1517
|
: {}),
|
|
1488
1518
|
...(_options.progressive
|
|
1489
1519
|
? {
|
|
@@ -1551,10 +1581,33 @@ function createFormControl(props = {}) {
|
|
|
1551
1581
|
iterateFieldsByAction(_fields, (ref, name) => {
|
|
1552
1582
|
const currentField = get(_fields, name);
|
|
1553
1583
|
if (currentField) {
|
|
1554
|
-
ref.disabled = currentField._f.disabled
|
|
1584
|
+
ref.disabled = isBoolean(currentField._f.disabled)
|
|
1585
|
+
? currentField._f.disabled
|
|
1586
|
+
: disabled;
|
|
1587
|
+
if (Array.isArray(currentField._f.refs)) {
|
|
1588
|
+
currentField._f.refs.forEach((inputRef) => {
|
|
1589
|
+
inputRef.disabled = isBoolean(currentField._f.disabled)
|
|
1590
|
+
? currentField._f.disabled
|
|
1591
|
+
: disabled;
|
|
1592
|
+
});
|
|
1593
|
+
}
|
|
1594
|
+
}
|
|
1595
|
+
}, 0, false);
|
|
1596
|
+
}
|
|
1597
|
+
else if (Array.isArray(disabled)) {
|
|
1598
|
+
// For array mode, we don't set the global disabled state
|
|
1599
|
+
// but we update individual fields based on their inclusion in the array
|
|
1600
|
+
iterateFieldsByAction(_fields, (ref, name) => {
|
|
1601
|
+
const currentField = get(_fields, name);
|
|
1602
|
+
if (currentField) {
|
|
1603
|
+
// Field-level disabled takes precedence over array disabled
|
|
1604
|
+
const isFieldDisabled = isBoolean(currentField._f.disabled)
|
|
1605
|
+
? currentField._f.disabled
|
|
1606
|
+
: new Set(disabled).has(name);
|
|
1607
|
+
ref.disabled = isFieldDisabled;
|
|
1555
1608
|
if (Array.isArray(currentField._f.refs)) {
|
|
1556
1609
|
currentField._f.refs.forEach((inputRef) => {
|
|
1557
|
-
inputRef.disabled =
|
|
1610
|
+
inputRef.disabled = isFieldDisabled;
|
|
1558
1611
|
});
|
|
1559
1612
|
}
|
|
1560
1613
|
}
|
|
@@ -1745,6 +1798,7 @@ function createFormControl(props = {}) {
|
|
|
1745
1798
|
? _formState.isSubmitSuccessful
|
|
1746
1799
|
: false,
|
|
1747
1800
|
isSubmitting: false,
|
|
1801
|
+
defaultValues: _defaultValues,
|
|
1748
1802
|
});
|
|
1749
1803
|
};
|
|
1750
1804
|
const reset = (formValues, keepStateOptions) => _reset(isFunction(formValues)
|