@bombillazo/rhf-plus 7.62.0-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.
@@ -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,CA0+CA"}
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"}
@@ -826,7 +826,9 @@ function createFormControl(props = {}) {
826
826
  dirtyFields: {},
827
827
  validatingFields: {},
828
828
  errors: _options.errors || {},
829
- disabled: _options.disabled || false,
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
@@ -1461,7 +1479,9 @@ function createFormControl(props = {}) {
1461
1479
  };
1462
1480
  const register = (name, options = {}) => {
1463
1481
  let field = get(_fields, name);
1464
- const disabledIsDefined = isBoolean(options.disabled) || isBoolean(_options.disabled);
1482
+ const disabledIsDefined = isBoolean(options.disabled) ||
1483
+ isBoolean(_options.disabled) ||
1484
+ Array.isArray(_options.disabled);
1465
1485
  set(_fields, name, {
1466
1486
  ...(field || {}),
1467
1487
  _f: {
@@ -1476,7 +1496,9 @@ function createFormControl(props = {}) {
1476
1496
  _setDisabledField({
1477
1497
  disabled: isBoolean(options.disabled)
1478
1498
  ? options.disabled
1479
- : _options.disabled,
1499
+ : Array.isArray(_options.disabled)
1500
+ ? new Set(_options.disabled).has(name)
1501
+ : _options.disabled,
1480
1502
  name,
1481
1503
  });
1482
1504
  }
@@ -1485,7 +1507,13 @@ function createFormControl(props = {}) {
1485
1507
  }
1486
1508
  return {
1487
1509
  ...(disabledIsDefined
1488
- ? { disabled: options.disabled || _options.disabled }
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
+ }
1489
1517
  : {}),
1490
1518
  ...(_options.progressive
1491
1519
  ? {
@@ -1553,10 +1581,33 @@ function createFormControl(props = {}) {
1553
1581
  iterateFieldsByAction(_fields, (ref, name) => {
1554
1582
  const currentField = get(_fields, name);
1555
1583
  if (currentField) {
1556
- ref.disabled = currentField._f.disabled || 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;
1557
1608
  if (Array.isArray(currentField._f.refs)) {
1558
1609
  currentField._f.refs.forEach((inputRef) => {
1559
- inputRef.disabled = currentField._f.disabled || disabled;
1610
+ inputRef.disabled = isFieldDisabled;
1560
1611
  });
1561
1612
  }
1562
1613
  }