@bombillazo/rhf-plus 7.56.4-plus.0 → 7.57.0-plus.0

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.
@@ -266,7 +266,7 @@ function useFormState(props) {
266
266
  errors: false,
267
267
  });
268
268
  useIsomorphicLayoutEffect(() => control._subscribe({
269
- name: name,
269
+ name,
270
270
  formState: _localProxyFormState.current,
271
271
  exact,
272
272
  callback: (formState) => {
@@ -319,7 +319,7 @@ function useWatch(props) {
319
319
  const _defaultValue = React__default.useRef(defaultValue);
320
320
  const [value, updateValue] = React__default.useState(control._getWatch(name, _defaultValue.current));
321
321
  useIsomorphicLayoutEffect(() => control._subscribe({
322
- name: name,
322
+ name,
323
323
  formState: {
324
324
  values: true,
325
325
  },
@@ -419,8 +419,8 @@ function useController(props) {
419
419
  const field = get(control._fields, name);
420
420
  if (field && elm) {
421
421
  field._f.ref = {
422
- focus: () => elm.focus(),
423
- select: () => elm.select(),
422
+ focus: () => elm.focus && elm.focus(),
423
+ select: () => elm.select && elm.select(),
424
424
  setCustomValidity: (message) => elm.setCustomValidity(message),
425
425
  reportValidity: () => elm.reportValidity(),
426
426
  };
@@ -1039,6 +1039,12 @@ function schemaErrorLookup(errors, _fields, name) {
1039
1039
  error: foundError,
1040
1040
  };
1041
1041
  }
1042
+ if (foundError && foundError.root && foundError.root.type) {
1043
+ return {
1044
+ name: `${fieldName}.root`,
1045
+ error: foundError.root,
1046
+ };
1047
+ }
1042
1048
  names.pop();
1043
1049
  }
1044
1050
  return {
@@ -1665,7 +1671,7 @@ function createFormControl(props = {}) {
1665
1671
  return;
1666
1672
  }
1667
1673
  const fieldValue = value[fieldKey];
1668
- const fieldName = `${name}.${fieldKey}`;
1674
+ const fieldName = name + '.' + fieldKey;
1669
1675
  const field = get(_fields, fieldName);
1670
1676
  (_names.array.has(name) ||
1671
1677
  isObject(fieldValue) ||
@@ -2307,6 +2313,7 @@ function createFormControl(props = {}) {
2307
2313
  setError,
2308
2314
  _subscribe,
2309
2315
  _runSchema,
2316
+ _focusError,
2310
2317
  _getWatch,
2311
2318
  _getDirty,
2312
2319
  _setValid,
@@ -2778,10 +2785,13 @@ function useForm(props = {}) {
2778
2785
  if (props.reValidateMode) {
2779
2786
  control._options.reValidateMode = props.reValidateMode;
2780
2787
  }
2781
- if (props.errors && !isEmptyObject(props.errors)) {
2788
+ }, [control, props.mode, props.reValidateMode]);
2789
+ React__default.useEffect(() => {
2790
+ if (props.errors) {
2782
2791
  control._setErrors(props.errors);
2792
+ control._focusError();
2783
2793
  }
2784
- }, [control, props.errors, props.mode, props.reValidateMode]);
2794
+ }, [control, props.errors]);
2785
2795
  React__default.useEffect(() => {
2786
2796
  props.shouldUnregister &&
2787
2797
  control._subjects.state.next({