@bombillazo/rhf-plus 7.62.0-plus.3 → 7.62.0-plus.5

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,CAoiDA"}
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,CAolDA"}
@@ -2,6 +2,10 @@ import type { ValidationModeFlags } from '../types';
2
2
  declare const _default: (isBlurEvent: boolean, isTouched: boolean, isSubmitted: boolean, reValidateMode: {
3
3
  isOnBlur: boolean;
4
4
  isOnChange: boolean;
5
- }, mode: Partial<ValidationModeFlags>) => boolean;
5
+ }, mode: Partial<ValidationModeFlags>,
6
+ /**
7
+ * Need to keep this order of parameters for backward compatibility
8
+ */
9
+ isFocusEvent: boolean) => boolean;
6
10
  export default _default;
7
11
  //# sourceMappingURL=skipValidation.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"skipValidation.d.ts","sourceRoot":"","sources":["../../src/logic/skipValidation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;yBAGlD,aAAa,OAAO,EACpB,WAAW,OAAO,EAClB,aAAa,OAAO,EACpB,gBAAgB;IACd,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,EAAE,OAAO,CAAC;CACrB,EACD,MAAM,OAAO,CAAC,mBAAmB,CAAC;AARpC,wBAoBE"}
1
+ {"version":3,"file":"skipValidation.d.ts","sourceRoot":"","sources":["../../src/logic/skipValidation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;yBAGlD,aAAa,OAAO,EACpB,WAAW,OAAO,EAClB,aAAa,OAAO,EACpB,gBAAgB;IACd,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,EAAE,OAAO,CAAC;CACrB,EACD,MAAM,OAAO,CAAC,mBAAmB,CAAC;AAClC;;GAEG;AACH,cAAc,OAAO;AAZvB,wBA6BE"}
@@ -13,7 +13,9 @@ var appendErrors = (name, validateAllFieldCriteria, errors, type, message) => va
13
13
 
14
14
  const EVENTS = {
15
15
  BLUR: 'blur',
16
- FOCUS_OUT: 'focusout'};
16
+ FOCUS_OUT: 'focusout',
17
+ FOCUS: 'focus',
18
+ FOCUS_IN: 'focusin'};
17
19
  const VALIDATION_MODE = {
18
20
  onBlur: 'onBlur',
19
21
  onChange: 'onChange',
@@ -577,7 +579,15 @@ var shouldSubscribeByName = (name, signalName, exact) => !name ||
577
579
  : currentName.startsWith(signalName) ||
578
580
  signalName.startsWith(currentName)));
579
581
 
580
- var skipValidation = (isBlurEvent, isTouched, isSubmitted, reValidateMode, mode) => {
582
+ var skipValidation = (isBlurEvent, isTouched, isSubmitted, reValidateMode, mode,
583
+ /**
584
+ * Need to keep this order of parameters for backward compatibility
585
+ */
586
+ isFocusEvent) => {
587
+ // Focus events should always skip validation
588
+ if (isFocusEvent) {
589
+ return true;
590
+ }
581
591
  if (mode.isOnAll) {
582
592
  return false;
583
593
  }
@@ -844,6 +854,7 @@ function createFormControl(props = {}) {
844
854
  isValid: false,
845
855
  touchedFields: {},
846
856
  dirtyFields: {},
857
+ focusedField: undefined,
847
858
  validatingFields: {},
848
859
  errors: _options.errors || {},
849
860
  disabled: Array.isArray(_options.disabled)
@@ -877,6 +888,7 @@ function createFormControl(props = {}) {
877
888
  dirtyFields: false,
878
889
  validatingFields: false,
879
890
  touchedFields: false,
891
+ focusedField: false,
880
892
  isValidating: false,
881
893
  isValid: false,
882
894
  errors: false,
@@ -988,7 +1000,7 @@ function createFormControl(props = {}) {
988
1000
  _state.mount && _setValid();
989
1001
  }
990
1002
  };
991
- const updateTouchAndDirty = (name, fieldValue, isBlurEvent, shouldDirty, shouldRender) => {
1003
+ const updateTouchAndDirty = (name, fieldValue, isBlurEvent, isFocusEvent, shouldDirty, shouldRender) => {
992
1004
  let shouldUpdateField = false;
993
1005
  let isPreviousDirty = false;
994
1006
  const output = {
@@ -1025,6 +1037,25 @@ function createFormControl(props = {}) {
1025
1037
  isPreviousFieldTouched !== isBlurEvent);
1026
1038
  }
1027
1039
  }
1040
+ // Handle focus state
1041
+ if (isFocusEvent || isBlurEvent) {
1042
+ const wasPreviouslyFocused = _formState.focusedField === name;
1043
+ const shouldBeFocused = isFocusEvent && !isBlurEvent;
1044
+ if (wasPreviouslyFocused !== shouldBeFocused) {
1045
+ if (shouldBeFocused) {
1046
+ _formState.focusedField = name;
1047
+ }
1048
+ else {
1049
+ _formState.focusedField = undefined;
1050
+ }
1051
+ output.focusedField = _formState.focusedField;
1052
+ shouldUpdateField =
1053
+ shouldUpdateField ||
1054
+ ((_proxyFormState.focusedField ||
1055
+ _proxySubscribeFormState.focusedField) &&
1056
+ wasPreviouslyFocused !== shouldBeFocused);
1057
+ }
1058
+ }
1028
1059
  shouldUpdateField && shouldRender && _subjects.state.next(output);
1029
1060
  }
1030
1061
  return shouldUpdateField ? output : {};
@@ -1190,7 +1221,8 @@ function createFormControl(props = {}) {
1190
1221
  }
1191
1222
  }
1192
1223
  (options.shouldDirty || options.shouldTouch) &&
1193
- updateTouchAndDirty(name, fieldValue, options.shouldTouch, options.shouldDirty, true);
1224
+ updateTouchAndDirty(name, fieldValue, options.shouldTouch, false, // isFocusEvent - not applicable for setValue
1225
+ options.shouldDirty, true);
1194
1226
  options.shouldValidate && trigger(name);
1195
1227
  };
1196
1228
  const setValues = (name, value, options) => {
@@ -1241,6 +1273,14 @@ function createFormControl(props = {}) {
1241
1273
  name: _state.mount ? name : undefined,
1242
1274
  values: cloneObject(_formValues),
1243
1275
  });
1276
+ // Trigger validation when shouldValidate is true
1277
+ // This ensures validation happens for all cases including:
1278
+ // - Field arrays
1279
+ // - Empty arrays
1280
+ // - Nested fields with array values
1281
+ if (options.shouldValidate) {
1282
+ trigger(name);
1283
+ }
1244
1284
  };
1245
1285
  const onChange = async (event) => {
1246
1286
  _state.mount = true;
@@ -1279,12 +1319,13 @@ function createFormControl(props = {}) {
1279
1319
  ? getFieldValue(field._f)
1280
1320
  : getEventValue(event);
1281
1321
  const isBlurEvent = event.type === EVENTS.BLUR || event.type === EVENTS.FOCUS_OUT;
1322
+ const isFocusEvent = event.type === EVENTS.FOCUS || event.type === EVENTS.FOCUS_IN;
1282
1323
  const shouldSkipValidation = (!hasValidation(field._f) &&
1283
1324
  !_options.resolver &&
1284
1325
  !get(_formState.errors, name) &&
1285
1326
  !field._f.deps) ||
1286
- skipValidation(isBlurEvent, get(_formState.touchedFields, name), _formState.isSubmitted, validationModeAfterSubmit, validationModeBeforeSubmit);
1287
- const watched = isWatched(name, _names, isBlurEvent);
1327
+ skipValidation(isBlurEvent, get(_formState.touchedFields, name), _formState.isSubmitted, validationModeAfterSubmit, validationModeBeforeSubmit, isFocusEvent);
1328
+ const watched = isWatched(name, _names, isBlurEvent || isFocusEvent);
1288
1329
  set(_formValues, name, fieldValue);
1289
1330
  if (isBlurEvent) {
1290
1331
  if (!target || !target.readOnly) {
@@ -1295,7 +1336,7 @@ function createFormControl(props = {}) {
1295
1336
  else if (field._f.onChange) {
1296
1337
  field._f.onChange(event);
1297
1338
  }
1298
- const fieldState = updateTouchAndDirty(name, fieldValue, isBlurEvent);
1339
+ const fieldState = updateTouchAndDirty(name, fieldValue, isBlurEvent, isFocusEvent);
1299
1340
  const shouldRender = !isEmptyObject(fieldState) || watched;
1300
1341
  !isBlurEvent &&
1301
1342
  _subjects.state.next({
@@ -1409,6 +1450,7 @@ function createFormControl(props = {}) {
1409
1450
  error: get((formState || _formState).errors, name),
1410
1451
  isValidating: !!get(_formState.validatingFields, name),
1411
1452
  isTouched: !!get((formState || _formState).touchedFields, name),
1453
+ isFocused: (formState || _formState).focusedField === name,
1412
1454
  });
1413
1455
  const clearErrors = (name) => {
1414
1456
  name &&
@@ -1548,6 +1590,7 @@ function createFormControl(props = {}) {
1548
1590
  name,
1549
1591
  onChange,
1550
1592
  onBlur: onChange,
1593
+ onFocus: onChange,
1551
1594
  ref: (ref) => {
1552
1595
  if (ref) {
1553
1596
  register(name, options);
@@ -1813,6 +1856,7 @@ function createFormControl(props = {}) {
1813
1856
  touchedFields: keepStateOptions.keepTouched
1814
1857
  ? _formState.touchedFields
1815
1858
  : {},
1859
+ focusedField: undefined, // Always reset focused field on form reset
1816
1860
  errors: keepStateOptions.keepErrors ? _formState.errors : {},
1817
1861
  isSubmitSuccessful: keepStateOptions.keepIsSubmitSuccessful
1818
1862
  ? _formState.isSubmitSuccessful