@bombillazo/rhf-plus 7.62.0-plus.1 → 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.
@@ -469,17 +469,26 @@ function useController(props) {
469
469
  },
470
470
  type: EVENTS.BLUR,
471
471
  }), [name, control._formValues]);
472
+ const elementRef = React.useRef(null);
472
473
  const ref = React.useCallback((elm) => {
474
+ elementRef.current = elm;
473
475
  const field = get(control._fields, name);
474
476
  if (field && elm) {
475
477
  field._f.ref = {
476
- focus: () => elm.focus && elm.focus(),
477
- select: () => elm.select && elm.select(),
478
+ focus: () => { var _a; return (_a = elm.focus) === null || _a === void 0 ? void 0 : _a.call(elm); },
479
+ select: () => { var _a; return (_a = elm.select) === null || _a === void 0 ? void 0 : _a.call(elm); },
478
480
  setCustomValidity: (message) => elm.setCustomValidity(message),
479
481
  reportValidity: () => elm.reportValidity(),
480
482
  };
481
483
  }
482
484
  }, [control._fields, name]);
485
+ // Add scrollIntoView method to the ref callback function
486
+ ref.scrollIntoView = React.useCallback((options) => {
487
+ if (elementRef.current &&
488
+ typeof elementRef.current.scrollIntoView === 'function') {
489
+ elementRef.current.scrollIntoView(options);
490
+ }
491
+ }, []);
483
492
  const field = React.useMemo(() => {
484
493
  // Calculate if this specific field should be disabled
485
494
  let isFieldDisabled;
@@ -1136,7 +1145,17 @@ var updateFieldArrayRootError = (errors, error, name) => {
1136
1145
  return errors;
1137
1146
  };
1138
1147
 
1139
- var isMessage = (value) => isString(value);
1148
+ var isMessage = (value) => {
1149
+ // Support strings (existing functionality)
1150
+ if (isString(value)) {
1151
+ return true;
1152
+ }
1153
+ // Support React elements only (not primitives like null, undefined, numbers)
1154
+ if (React.isValidElement(value)) {
1155
+ return true;
1156
+ }
1157
+ return false;
1158
+ };
1140
1159
 
1141
1160
  function getValidateError(result, ref, type = 'validate') {
1142
1161
  if (isMessage(result) ||
@@ -1166,7 +1185,16 @@ var validateField = async (field, disabledFieldNames, formValues, validateAllFie
1166
1185
  const inputRef = refs ? refs[0] : ref;
1167
1186
  const setCustomValidity = (message) => {
1168
1187
  if (shouldUseNativeValidation && inputRef.reportValidity) {
1169
- inputRef.setCustomValidity(isBoolean(message) ? '' : message || '');
1188
+ if (isBoolean(message)) {
1189
+ inputRef.setCustomValidity('');
1190
+ }
1191
+ else if (typeof message === 'string') {
1192
+ inputRef.setCustomValidity(message || '');
1193
+ }
1194
+ else {
1195
+ // For ReactNode messages, convert to string or use empty string for native validation
1196
+ inputRef.setCustomValidity('');
1197
+ }
1170
1198
  inputRef.reportValidity();
1171
1199
  }
1172
1200
  };