@tanstack/form-core 0.30.0 → 0.32.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.
package/src/FormApi.ts CHANGED
@@ -259,6 +259,10 @@ export type FormState<TFormData> = {
259
259
  * A boolean indicating if any of the form fields have been touched.
260
260
  */
261
261
  isTouched: boolean
262
+ /**
263
+ * A boolean indicating if any of the form fields have been blurred.
264
+ */
265
+ isBlurred: boolean
262
266
  /**
263
267
  * A boolean indicating if any of the form's fields' values have been modified by the user. `True` if the user have modified at least one of the fields. Opposite of `isPristine`.
264
268
  */
@@ -305,6 +309,7 @@ function getDefaultFormState<TFormData>(
305
309
  isSubmitted: defaultState.isSubmitted ?? false,
306
310
  isSubmitting: defaultState.isSubmitting ?? false,
307
311
  isTouched: defaultState.isTouched ?? false,
312
+ isBlurred: defaultState.isBlurred ?? false,
308
313
  isPristine: defaultState.isPristine ?? true,
309
314
  isDirty: defaultState.isDirty ?? false,
310
315
  isValid: defaultState.isValid ?? false,
@@ -388,6 +393,7 @@ export class FormApi<
388
393
  )
389
394
 
390
395
  const isTouched = fieldMetaValues.some((field) => field?.isTouched)
396
+ const isBlurred = fieldMetaValues.some((field) => field?.isBlurred)
391
397
 
392
398
  const isDirty = fieldMetaValues.some((field) => field?.isDirty)
393
399
  const isPristine = !isDirty
@@ -410,6 +416,7 @@ export class FormApi<
410
416
  isValid,
411
417
  canSubmit,
412
418
  isTouched,
419
+ isBlurred,
413
420
  isPristine,
414
421
  isDirty,
415
422
  }
@@ -553,6 +560,12 @@ export class FormApi<
553
560
  // Mark them as touched
554
561
  field.instance.setMeta((prev) => ({ ...prev, isTouched: true }))
555
562
  }
563
+
564
+ // If any fields are not blurred
565
+ if (!field.instance.state.meta.isBlurred) {
566
+ // Mark them as blurred
567
+ field.instance.setMeta((prev) => ({ ...prev, isBlurred: true }))
568
+ }
556
569
  })
557
570
  })
558
571
 
@@ -616,6 +629,12 @@ export class FormApi<
616
629
  fieldInstance.setMeta((prev) => ({ ...prev, isTouched: true }))
617
630
  }
618
631
 
632
+ // If the field is not blurred (same logic as in validateAllFields)
633
+ if (!fieldInstance.state.meta.isBlurred) {
634
+ // Mark it as blurred
635
+ fieldInstance.setMeta((prev) => ({ ...prev, isBlurred: true }))
636
+ }
637
+
619
638
  return fieldInstance.validate(cause)
620
639
  }
621
640
 
@@ -983,6 +1002,7 @@ export class FormApi<
983
1002
  acc[fieldKey] = {
984
1003
  isValidating: false,
985
1004
  isTouched: false,
1005
+ isBlurred: false,
986
1006
  isDirty: false,
987
1007
  isPristine: true,
988
1008
  errors: [],
@@ -1009,6 +1029,7 @@ export class FormApi<
1009
1029
  this.setFieldMeta(field, (prev) => ({
1010
1030
  ...prev,
1011
1031
  isTouched: true,
1032
+ isBlurred: true,
1012
1033
  isDirty: true,
1013
1034
  }))
1014
1035
  }
package/src/types.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type DeepKeys } from './util-types'
1
+ import type { DeepKeys } from './util-types'
2
2
 
3
3
  export type ValidationError = undefined | false | null | string
4
4