@bombillazo/rhf-plus 7.62.0-plus.0 → 7.62.0-plus.2

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"}
@@ -1 +1 @@
1
- {"version":3,"file":"getValidateError.d.ts","sourceRoot":"","sources":["../../src/logic/getValidateError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,GAAG,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAIhE,MAAM,CAAC,OAAO,UAAU,gBAAgB,CACtC,MAAM,EAAE,cAAc,EACtB,GAAG,EAAE,GAAG,EACR,IAAI,SAAa,GAChB,UAAU,GAAG,IAAI,CAYnB"}
1
+ {"version":3,"file":"getValidateError.d.ts","sourceRoot":"","sources":["../../src/logic/getValidateError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAW,GAAG,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAIzE,MAAM,CAAC,OAAO,UAAU,gBAAgB,CACtC,MAAM,EAAE,cAAc,EACtB,GAAG,EAAE,GAAG,EACR,IAAI,SAAa,GAChB,UAAU,GAAG,IAAI,CAYnB"}
@@ -1,5 +1,5 @@
1
1
  import type { ValidationRule } from '../types';
2
- declare const _default: (validationData?: ValidationRule) => {
2
+ declare const _default: (validationData?: ValidationRule) => import("../types").ValidationValueMessage<import("../types").ValidationValue> | {
3
3
  value: string | number | boolean | RegExp | undefined;
4
4
  message: string;
5
5
  };
@@ -1,4 +1,4 @@
1
1
  import type { Field } from '../types';
2
- declare const _default: (options: Field["_f"]) => string | number | boolean | import("../types").ValidationValueMessage<boolean> | import("../types").ValidationValueMessage<string | number> | import("../types").ValidationRule<RegExp> | import("../types").Validate<any, import("../types").FieldValues> | Record<string, import("../types").Validate<any, import("../types").FieldValues>> | undefined;
2
+ declare const _default: (options: Field["_f"]) => string | number | boolean | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | import("../types").ValidationValueMessage<boolean> | import("../types").ValidationValueMessage<string | number> | import("../types").ValidationRule<RegExp> | import("../types").Validate<any, import("../types").FieldValues> | Record<string, import("../types").Validate<any, import("../types").FieldValues>> | undefined;
3
3
  export default _default;
4
4
  //# sourceMappingURL=hasValidation.d.ts.map
@@ -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;yBAsBI,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"}
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;yBAsBI,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,wBAoQE"}
@@ -1,4 +1,5 @@
1
1
  import crypto from 'crypto';
2
+ import React from 'react';
2
3
 
3
4
  var appendErrors = (name, validateAllFieldCriteria, errors, type, message) => validateAllFieldCriteria
4
5
  ? {
@@ -601,7 +602,17 @@ var updateFieldArrayRootError = (errors, error, name) => {
601
602
  return errors;
602
603
  };
603
604
 
604
- var isMessage = (value) => isString(value);
605
+ var isMessage = (value) => {
606
+ // Support strings (existing functionality)
607
+ if (isString(value)) {
608
+ return true;
609
+ }
610
+ // Support React elements only (not primitives like null, undefined, numbers)
611
+ if (React.isValidElement(value)) {
612
+ return true;
613
+ }
614
+ return false;
615
+ };
605
616
 
606
617
  function getValidateError(result, ref, type = 'validate') {
607
618
  if (isMessage(result) ||
@@ -631,7 +642,16 @@ var validateField = async (field, disabledFieldNames, formValues, validateAllFie
631
642
  const inputRef = refs ? refs[0] : ref;
632
643
  const setCustomValidity = (message) => {
633
644
  if (shouldUseNativeValidation && inputRef.reportValidity) {
634
- inputRef.setCustomValidity(isBoolean(message) ? '' : message || '');
645
+ if (isBoolean(message)) {
646
+ inputRef.setCustomValidity('');
647
+ }
648
+ else if (typeof message === 'string') {
649
+ inputRef.setCustomValidity(message || '');
650
+ }
651
+ else {
652
+ // For ReactNode messages, convert to string or use empty string for native validation
653
+ inputRef.setCustomValidity('');
654
+ }
635
655
  inputRef.reportValidity();
636
656
  }
637
657
  };
@@ -826,7 +846,9 @@ function createFormControl(props = {}) {
826
846
  dirtyFields: {},
827
847
  validatingFields: {},
828
848
  errors: _options.errors || {},
829
- disabled: _options.disabled || false,
849
+ disabled: Array.isArray(_options.disabled)
850
+ ? false
851
+ : _options.disabled || false,
830
852
  metadata: _options.defaultMetadata || {},
831
853
  };
832
854
  let _fields = {};
@@ -873,7 +895,7 @@ function createFormControl(props = {}) {
873
895
  timer = setTimeout(callback, wait);
874
896
  };
875
897
  const _setValid = async (shouldUpdateValid) => {
876
- if (!_options.disabled &&
898
+ if ((Array.isArray(_options.disabled) || !_options.disabled) &&
877
899
  (_proxyFormState.isValid ||
878
900
  _proxySubscribeFormState.isValid ||
879
901
  shouldUpdateValid)) {
@@ -1235,6 +1257,22 @@ function createFormControl(props = {}) {
1235
1257
  const validationModeBeforeSubmit = getValidationModes(_options.mode);
1236
1258
  const validationModeAfterSubmit = getValidationModes(_options.reValidateMode);
1237
1259
  if (field) {
1260
+ // Check if field is disabled and should not process events
1261
+ const isFieldDisabled = isBoolean(field._f.disabled)
1262
+ ? field._f.disabled
1263
+ : isBoolean(_options.disabled)
1264
+ ? _options.disabled
1265
+ : Array.isArray(_options.disabled)
1266
+ ? new Set(_options.disabled).has(name)
1267
+ : false;
1268
+ if (isFieldDisabled) {
1269
+ // Restore the original value if the field is disabled
1270
+ const originalValue = get(_formValues, name);
1271
+ if (target.value !== originalValue) {
1272
+ target.value = originalValue;
1273
+ }
1274
+ return;
1275
+ }
1238
1276
  let error;
1239
1277
  let isValid;
1240
1278
  const fieldValue = target.type
@@ -1461,7 +1499,9 @@ function createFormControl(props = {}) {
1461
1499
  };
1462
1500
  const register = (name, options = {}) => {
1463
1501
  let field = get(_fields, name);
1464
- const disabledIsDefined = isBoolean(options.disabled) || isBoolean(_options.disabled);
1502
+ const disabledIsDefined = isBoolean(options.disabled) ||
1503
+ isBoolean(_options.disabled) ||
1504
+ Array.isArray(_options.disabled);
1465
1505
  set(_fields, name, {
1466
1506
  ...(field || {}),
1467
1507
  _f: {
@@ -1476,7 +1516,9 @@ function createFormControl(props = {}) {
1476
1516
  _setDisabledField({
1477
1517
  disabled: isBoolean(options.disabled)
1478
1518
  ? options.disabled
1479
- : _options.disabled,
1519
+ : Array.isArray(_options.disabled)
1520
+ ? new Set(_options.disabled).has(name)
1521
+ : _options.disabled,
1480
1522
  name,
1481
1523
  });
1482
1524
  }
@@ -1485,7 +1527,13 @@ function createFormControl(props = {}) {
1485
1527
  }
1486
1528
  return {
1487
1529
  ...(disabledIsDefined
1488
- ? { disabled: options.disabled || _options.disabled }
1530
+ ? {
1531
+ disabled: isBoolean(options.disabled)
1532
+ ? options.disabled
1533
+ : Array.isArray(_options.disabled)
1534
+ ? new Set(_options.disabled).has(name)
1535
+ : !!_options.disabled,
1536
+ }
1489
1537
  : {}),
1490
1538
  ...(_options.progressive
1491
1539
  ? {
@@ -1553,10 +1601,33 @@ function createFormControl(props = {}) {
1553
1601
  iterateFieldsByAction(_fields, (ref, name) => {
1554
1602
  const currentField = get(_fields, name);
1555
1603
  if (currentField) {
1556
- ref.disabled = currentField._f.disabled || disabled;
1604
+ ref.disabled = isBoolean(currentField._f.disabled)
1605
+ ? currentField._f.disabled
1606
+ : disabled;
1607
+ if (Array.isArray(currentField._f.refs)) {
1608
+ currentField._f.refs.forEach((inputRef) => {
1609
+ inputRef.disabled = isBoolean(currentField._f.disabled)
1610
+ ? currentField._f.disabled
1611
+ : disabled;
1612
+ });
1613
+ }
1614
+ }
1615
+ }, 0, false);
1616
+ }
1617
+ else if (Array.isArray(disabled)) {
1618
+ // For array mode, we don't set the global disabled state
1619
+ // but we update individual fields based on their inclusion in the array
1620
+ iterateFieldsByAction(_fields, (ref, name) => {
1621
+ const currentField = get(_fields, name);
1622
+ if (currentField) {
1623
+ // Field-level disabled takes precedence over array disabled
1624
+ const isFieldDisabled = isBoolean(currentField._f.disabled)
1625
+ ? currentField._f.disabled
1626
+ : new Set(disabled).has(name);
1627
+ ref.disabled = isFieldDisabled;
1557
1628
  if (Array.isArray(currentField._f.refs)) {
1558
1629
  currentField._f.refs.forEach((inputRef) => {
1559
- inputRef.disabled = currentField._f.disabled || disabled;
1630
+ inputRef.disabled = isFieldDisabled;
1560
1631
  });
1561
1632
  }
1562
1633
  }