@bombillazo/rhf-plus 7.67.0-plus.0 → 7.69.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.
@@ -1 +1 @@
1
- {"version":3,"file":"createFormControl.d.ts","sourceRoot":"","sources":["../../src/logic/createFormControl.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAaV,WAAW,EACX,YAAY,EAiBZ,YAAY,EAIZ,aAAa,EAUd,MAAM,UAAU,CAAC;AAyDlB,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,CA6wDA"}
1
+ {"version":3,"file":"createFormControl.d.ts","sourceRoot":"","sources":["../../src/logic/createFormControl.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAaV,WAAW,EACX,YAAY,EAiBZ,YAAY,EAIZ,aAAa,EAUd,MAAM,UAAU,CAAC;AAyDlB,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,CA0yDA"}
@@ -52,29 +52,23 @@ var isWeb = typeof window !== 'undefined' &&
52
52
  typeof document !== 'undefined';
53
53
 
54
54
  function cloneObject(data) {
55
- let copy;
56
- const isArray = Array.isArray(data);
57
- const isFileListInstance = typeof FileList !== 'undefined' ? data instanceof FileList : false;
58
55
  if (data instanceof Date) {
59
- copy = new Date(data);
56
+ return new Date(data);
60
57
  }
61
- else if (!(isWeb && (data instanceof Blob || isFileListInstance)) &&
62
- (isArray || isObject(data))) {
63
- copy = isArray ? [] : Object.create(Object.getPrototypeOf(data));
64
- if (!isArray && !isPlainObject(data)) {
65
- copy = data;
66
- }
67
- else {
68
- for (const key in data) {
69
- if (data.hasOwnProperty(key)) {
70
- copy[key] = cloneObject(data[key]);
71
- }
72
- }
73
- }
58
+ const isFileListInstance = typeof FileList !== 'undefined' && data instanceof FileList;
59
+ if (isWeb && (data instanceof Blob || isFileListInstance)) {
60
+ return data;
74
61
  }
75
- else {
62
+ const isArray = Array.isArray(data);
63
+ if (!isArray && !(isObject(data) && isPlainObject(data))) {
76
64
  return data;
77
65
  }
66
+ const copy = isArray ? [] : Object.create(Object.getPrototypeOf(data));
67
+ for (const key in data) {
68
+ if (Object.prototype.hasOwnProperty.call(data, key)) {
69
+ copy[key] = cloneObject(data[key]);
70
+ }
71
+ }
78
72
  return copy;
79
73
  }
80
74
 
@@ -887,6 +881,7 @@ function createFormControl(props = {}) {
887
881
  action: false,
888
882
  mount: false,
889
883
  watch: false,
884
+ keepIsValid: false,
890
885
  };
891
886
  let _names = {
892
887
  mount: new Set(),
@@ -898,7 +893,7 @@ function createFormControl(props = {}) {
898
893
  };
899
894
  let delayErrorCallback;
900
895
  let timer = 0;
901
- const _proxyFormState = {
896
+ const defaultProxyFormState = {
902
897
  isDirty: false,
903
898
  isDirtySinceSubmit: false,
904
899
  hasBeenSubmitted: false,
@@ -910,6 +905,9 @@ function createFormControl(props = {}) {
910
905
  isValid: false,
911
906
  errors: false,
912
907
  };
908
+ const _proxyFormState = {
909
+ ...defaultProxyFormState,
910
+ };
913
911
  let _proxySubscribeFormState = {
914
912
  ..._proxyFormState,
915
913
  };
@@ -926,13 +924,21 @@ function createFormControl(props = {}) {
926
924
  timer = setTimeout(callback, wait);
927
925
  };
928
926
  const _setValid = async (shouldUpdateValid) => {
927
+ if (_state.keepIsValid) {
928
+ return;
929
+ }
929
930
  if ((Array.isArray(_options.disabled) || !_options.disabled) &&
930
931
  (_proxyFormState.isValid ||
931
932
  _proxySubscribeFormState.isValid ||
932
933
  shouldUpdateValid)) {
933
- const isValid = _options.resolver
934
- ? isEmptyObject((await _runSchema()).errors)
935
- : await executeBuiltInValidation(_fields, true);
934
+ let isValid;
935
+ if (_options.resolver) {
936
+ isValid = isEmptyObject((await _runSchema()).errors);
937
+ _updateIsValidating();
938
+ }
939
+ else {
940
+ isValid = await executeBuiltInValidation(_fields, true);
941
+ }
936
942
  if (isValid !== _formState.isValid) {
937
943
  _subjects.state.next({
938
944
  isValid,
@@ -1128,11 +1134,11 @@ function createFormControl(props = {}) {
1128
1134
  const _runSchema = async (name) => {
1129
1135
  _updateIsValidating(name, true);
1130
1136
  const result = await _options.resolver(_formValues, _options.context, getResolverOptions(name || _names.mount, _fields, _options.criteriaMode, _options.shouldUseNativeValidation));
1131
- _updateIsValidating(name);
1132
1137
  return result;
1133
1138
  };
1134
1139
  const executeSchemaAndUpdateState = async (names) => {
1135
1140
  const { errors } = await _runSchema(names);
1141
+ _updateIsValidating(names);
1136
1142
  if (names) {
1137
1143
  for (const name of names) {
1138
1144
  const error = get(errors, name);
@@ -1458,6 +1464,7 @@ function createFormControl(props = {}) {
1458
1464
  !isBlurEvent && watched && _subjects.state.next({ ..._formState });
1459
1465
  if (_options.resolver) {
1460
1466
  const { errors } = await _runSchema([name]);
1467
+ _updateIsValidating([name]);
1461
1468
  _updateIsFieldValueUpdated(fieldValue);
1462
1469
  if (isFieldValueUpdated) {
1463
1470
  const previousErrorLookupResult = schemaErrorLookup(_formState.errors, _fields, name);
@@ -1609,7 +1616,10 @@ function createFormControl(props = {}) {
1609
1616
  };
1610
1617
  return _subscribe({
1611
1618
  ...props,
1612
- formState: _proxySubscribeFormState,
1619
+ formState: {
1620
+ ...defaultProxyFormState,
1621
+ ...props.formState,
1622
+ },
1613
1623
  });
1614
1624
  };
1615
1625
  const unregister = (name, options = {}) => {
@@ -1803,6 +1813,7 @@ function createFormControl(props = {}) {
1803
1813
  });
1804
1814
  if (_options.resolver) {
1805
1815
  const { errors, values } = await _runSchema();
1816
+ _updateIsValidating();
1806
1817
  _formState.errors = errors;
1807
1818
  fieldValues = cloneObject(values);
1808
1819
  }
@@ -1947,6 +1958,14 @@ function createFormControl(props = {}) {
1947
1958
  !!keepStateOptions.keepDirtyValues ||
1948
1959
  (!_options.shouldUnregister && !isEmptyObject(values));
1949
1960
  _state.watch = !!_options.shouldUnregister;
1961
+ _state.keepIsValid = !!keepStateOptions.keepIsValid;
1962
+ _state.action = false;
1963
+ // Clear errors synchronously to prevent validation errors on subsequent submissions
1964
+ // This fixes the issue where form.reset() causes validation errors on subsequent
1965
+ // submissions in Next.js 16 with Server Actions
1966
+ if (!keepStateOptions.keepErrors) {
1967
+ _formState.errors = {};
1968
+ }
1950
1969
  _subjects.state.next({
1951
1970
  submitCount: keepStateOptions.keepSubmitCount
1952
1971
  ? _formState.submitCount
@@ -1987,7 +2006,7 @@ function createFormControl(props = {}) {
1987
2006
  };
1988
2007
  const reset = (formValues, keepStateOptions) => _reset(isFunction(formValues)
1989
2008
  ? formValues(_formValues)
1990
- : formValues, keepStateOptions);
2009
+ : formValues, { ..._options.resetOptions, ...keepStateOptions });
1991
2010
  const setFocus = (name, options = {}) => {
1992
2011
  const field = get(_fields, name);
1993
2012
  const fieldReference = field && field._f;
@@ -1996,10 +2015,14 @@ function createFormControl(props = {}) {
1996
2015
  ? fieldReference.refs[0]
1997
2016
  : fieldReference.ref;
1998
2017
  if (fieldRef.focus) {
1999
- fieldRef.focus();
2000
- options.shouldSelect &&
2001
- isFunction(fieldRef.select) &&
2002
- fieldRef.select();
2018
+ // Use setTimeout to ensure focus happens after any pending state updates
2019
+ // This fixes the issue where setFocus doesn't work immediately after setError
2020
+ setTimeout(() => {
2021
+ fieldRef.focus();
2022
+ options.shouldSelect &&
2023
+ isFunction(fieldRef.select) &&
2024
+ fieldRef.select();
2025
+ });
2003
2026
  }
2004
2027
  }
2005
2028
  };
@@ -2090,6 +2113,7 @@ function createFormControl(props = {}) {
2090
2113
  setError,
2091
2114
  _subscribe,
2092
2115
  _runSchema,
2116
+ _updateIsValidating,
2093
2117
  _focusError,
2094
2118
  _getWatch,
2095
2119
  _getDirty,