@@ -14,6 +14,7 @@ import type {
14
14
FieldInfo ,
15
15
FormApi ,
16
16
FormAsyncValidateOrFn ,
17
+ FormState ,
17
18
FormValidateAsyncFn ,
18
19
FormValidateFn ,
19
20
FormValidateOrFn ,
@@ -92,6 +93,7 @@ export type FieldValidateFn<
92
93
any ,
93
94
any ,
94
95
any ,
96
+ any ,
95
97
any
96
98
>
97
99
} ) => unknown
@@ -176,6 +178,7 @@ export type FieldValidateAsyncFn<
176
178
any ,
177
179
any ,
178
180
any ,
181
+ any ,
179
182
any
180
183
>
181
184
signal : AbortSignal
@@ -259,10 +262,39 @@ export type FieldListenerFn<
259
262
any ,
260
263
any ,
261
264
any ,
265
+ any ,
262
266
any
263
267
>
264
268
} ) => void
265
269
270
+ /**
271
+ * @private
272
+ */
273
+ export type FieldMetaFn <
274
+ TParentData ,
275
+ TFormOnMount extends undefined | FormValidateOrFn < TParentData > ,
276
+ TFormOnChange extends undefined | FormValidateOrFn < TParentData > ,
277
+ TFormOnChangeAsync extends undefined | FormAsyncValidateOrFn < TParentData > ,
278
+ TFormOnBlur extends undefined | FormValidateOrFn < TParentData > ,
279
+ TFormOnBlurAsync extends undefined | FormAsyncValidateOrFn < TParentData > ,
280
+ TFormOnSubmit extends undefined | FormValidateOrFn < TParentData > ,
281
+ TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn < TParentData > ,
282
+ TFormOnServer extends undefined | FormAsyncValidateOrFn < TParentData > ,
283
+ TFieldMetaExtension extends object ,
284
+ > = (
285
+ props : FormState <
286
+ TParentData ,
287
+ TFormOnMount ,
288
+ TFormOnChange ,
289
+ TFormOnChangeAsync ,
290
+ TFormOnBlur ,
291
+ TFormOnBlurAsync ,
292
+ TFormOnSubmit ,
293
+ TFormOnSubmitAsync ,
294
+ TFormOnServer
295
+ > ,
296
+ ) => TFieldMetaExtension
297
+
266
298
export interface FieldValidators <
267
299
TParentData ,
268
300
TName extends DeepKeys < TParentData > ,
@@ -375,6 +407,15 @@ export interface FieldOptions<
375
407
TOnSubmitAsync extends
376
408
| undefined
377
409
| FieldAsyncValidateOrFn < TParentData , TName , TData > ,
410
+ TFormOnMount extends undefined | FormValidateOrFn < TParentData > ,
411
+ TFormOnChange extends undefined | FormValidateOrFn < TParentData > ,
412
+ TFormOnChangeAsync extends undefined | FormAsyncValidateOrFn < TParentData > ,
413
+ TFormOnBlur extends undefined | FormValidateOrFn < TParentData > ,
414
+ TFormOnBlurAsync extends undefined | FormAsyncValidateOrFn < TParentData > ,
415
+ TFormOnSubmit extends undefined | FormValidateOrFn < TParentData > ,
416
+ TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn < TParentData > ,
417
+ TFormOnServer extends undefined | FormAsyncValidateOrFn < TParentData > ,
418
+ TFieldMetaExtension extends object ,
378
419
> {
379
420
/**
380
421
* The field name. The type will be `DeepKeys<TParentData>` to ensure your name is a deep key of the parent dataset.
@@ -428,13 +469,30 @@ export interface FieldOptions<
428
469
any ,
429
470
any ,
430
471
any ,
431
- any
472
+ any ,
473
+ TFieldMetaExtension
432
474
>
433
475
>
434
476
/**
435
477
* A list of listeners which attach to the corresponding events
436
478
*/
437
479
listeners ?: FieldListeners < TParentData , TName , TData >
480
+
481
+ /**
482
+ * A list of listeners which attach to the corresponding events
483
+ */
484
+ meta ?: FieldMetaFn <
485
+ TParentData ,
486
+ TFormOnMount ,
487
+ TFormOnChange ,
488
+ TFormOnChangeAsync ,
489
+ TFormOnBlur ,
490
+ TFormOnBlurAsync ,
491
+ TFormOnSubmit ,
492
+ TFormOnSubmitAsync ,
493
+ TFormOnServer ,
494
+ TFieldMetaExtension
495
+ >
438
496
/**
439
497
* Disable the `flat(1)` operation on `field.errors`. This is useful if you want to keep the error structure as is. Not suggested for most use-cases.
440
498
*/
@@ -470,6 +528,7 @@ export interface FieldApiOptions<
470
528
TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn < TParentData > ,
471
529
TFormOnServer extends undefined | FormAsyncValidateOrFn < TParentData > ,
472
530
TParentSubmitMeta ,
531
+ TFieldMetaExtension extends object ,
473
532
> extends FieldOptions <
474
533
TParentData ,
475
534
TName ,
@@ -480,7 +539,16 @@ export interface FieldApiOptions<
480
539
TOnBlur ,
481
540
TOnBlurAsync ,
482
541
TOnSubmit ,
483
- TOnSubmitAsync
542
+ TOnSubmitAsync ,
543
+ TFormOnMount ,
544
+ TFormOnChange ,
545
+ TFormOnChangeAsync ,
546
+ TFormOnBlur ,
547
+ TFormOnBlurAsync ,
548
+ TFormOnSubmit ,
549
+ TFormOnSubmitAsync ,
550
+ TFormOnServer ,
551
+ TFieldMetaExtension
484
552
> {
485
553
form : FormApi <
486
554
TParentData ,
@@ -520,6 +588,7 @@ export type FieldMetaBase<
520
588
TFormOnBlurAsync extends undefined | FormAsyncValidateOrFn < TParentData > ,
521
589
TFormOnSubmit extends undefined | FormValidateOrFn < TParentData > ,
522
590
TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn < TParentData > ,
591
+ TFieldMetaExtension extends object = { } ,
523
592
> = {
524
593
/**
525
594
* A flag indicating whether the field has been touched.
@@ -564,7 +633,7 @@ export type FieldMetaBase<
564
633
* A flag indicating whether the field is currently being validated.
565
634
*/
566
635
isValidating : boolean
567
- }
636
+ } & TFieldMetaExtension
568
637
569
638
export type AnyFieldMetaBase = FieldMetaBase <
570
639
any ,
@@ -583,6 +652,7 @@ export type AnyFieldMetaBase = FieldMetaBase<
583
652
any ,
584
653
any ,
585
654
any ,
655
+ any ,
586
656
any
587
657
>
588
658
@@ -610,6 +680,7 @@ export type FieldMetaDerived<
610
680
TFormOnBlurAsync extends undefined | FormAsyncValidateOrFn < TParentData > ,
611
681
TFormOnSubmit extends undefined | FormValidateOrFn < TParentData > ,
612
682
TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn < TParentData > ,
683
+ TFieldMetaExtension extends object = { } ,
613
684
> = {
614
685
/**
615
686
* An array of errors related to the field value.
@@ -656,7 +727,7 @@ export type FieldMetaDerived<
656
727
* A flag that is `true` if the field's value has not been modified by the user. Opposite of `isDirty`.
657
728
*/
658
729
isPristine : boolean
659
- }
730
+ } & TFieldMetaExtension
660
731
661
732
export type AnyFieldMetaDerived = FieldMetaDerived <
662
733
any ,
@@ -675,6 +746,7 @@ export type AnyFieldMetaDerived = FieldMetaDerived<
675
746
any ,
676
747
any ,
677
748
any ,
749
+ any ,
678
750
any
679
751
>
680
752
@@ -705,6 +777,7 @@ export type FieldMeta<
705
777
TFormOnBlurAsync extends undefined | FormAsyncValidateOrFn < TParentData > ,
706
778
TFormOnSubmit extends undefined | FormValidateOrFn < TParentData > ,
707
779
TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn < TParentData > ,
780
+ TFieldMetaExtension extends object = { } ,
708
781
> = FieldMetaBase <
709
782
TParentData ,
710
783
TName ,
@@ -722,7 +795,8 @@ export type FieldMeta<
722
795
TFormOnBlur ,
723
796
TFormOnBlurAsync ,
724
797
TFormOnSubmit ,
725
- TFormOnSubmitAsync
798
+ TFormOnSubmitAsync ,
799
+ TFieldMetaExtension
726
800
> &
727
801
FieldMetaDerived <
728
802
TParentData ,
@@ -741,7 +815,8 @@ export type FieldMeta<
741
815
TFormOnBlur ,
742
816
TFormOnBlurAsync ,
743
817
TFormOnSubmit ,
744
- TFormOnSubmitAsync
818
+ TFormOnSubmitAsync ,
819
+ TFieldMetaExtension
745
820
>
746
821
747
822
export type AnyFieldMeta = FieldMeta <
@@ -761,6 +836,7 @@ export type AnyFieldMeta = FieldMeta<
761
836
any ,
762
837
any ,
763
838
any ,
839
+ any ,
764
840
any
765
841
>
766
842
@@ -791,6 +867,7 @@ export type FieldState<
791
867
TFormOnBlurAsync extends undefined | FormAsyncValidateOrFn < TParentData > ,
792
868
TFormOnSubmit extends undefined | FormValidateOrFn < TParentData > ,
793
869
TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn < TParentData > ,
870
+ TFieldMetaExtension extends object ,
794
871
> = {
795
872
/**
796
873
* The current value of the field.
@@ -816,7 +893,8 @@ export type FieldState<
816
893
TFormOnBlur ,
817
894
TFormOnBlurAsync ,
818
895
TFormOnSubmit ,
819
- TFormOnSubmitAsync
896
+ TFormOnSubmitAsync ,
897
+ TFieldMetaExtension
820
898
>
821
899
}
822
900
@@ -844,6 +922,7 @@ export type AnyFieldApi = FieldApi<
844
922
any ,
845
923
any ,
846
924
any ,
925
+ any ,
847
926
any
848
927
>
849
928
@@ -882,6 +961,7 @@ export class FieldApi<
882
961
TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn < TParentData > ,
883
962
TFormOnServer extends undefined | FormAsyncValidateOrFn < TParentData > ,
884
963
TParentSubmitMeta ,
964
+ TFieldMetaExtension extends object ,
885
965
> {
886
966
/**
887
967
* A reference to the form API instance.
@@ -905,7 +985,8 @@ export class FieldApi<
905
985
TFormOnSubmit ,
906
986
TFormOnSubmitAsync ,
907
987
TFormOnServer ,
908
- TParentSubmitMeta
988
+ TParentSubmitMeta ,
989
+ TFieldMetaExtension
909
990
> [ 'form' ]
910
991
/**
911
992
* The field name.
@@ -933,7 +1014,8 @@ export class FieldApi<
933
1014
TFormOnSubmit ,
934
1015
TFormOnSubmitAsync ,
935
1016
TFormOnServer ,
936
- TParentSubmitMeta
1017
+ TParentSubmitMeta ,
1018
+ TFieldMetaExtension
937
1019
> = { } as any
938
1020
/**
939
1021
* The field state store.
@@ -956,7 +1038,8 @@ export class FieldApi<
956
1038
TFormOnBlur ,
957
1039
TFormOnBlurAsync ,
958
1040
TFormOnSubmit ,
959
- TFormOnSubmitAsync
1041
+ TFormOnSubmitAsync ,
1042
+ TFieldMetaExtension
960
1043
>
961
1044
>
962
1045
/**
@@ -990,7 +1073,8 @@ export class FieldApi<
990
1073
TFormOnSubmit ,
991
1074
TFormOnSubmitAsync ,
992
1075
TFormOnServer ,
993
- TParentSubmitMeta
1076
+ TParentSubmitMeta ,
1077
+ TFieldMetaExtension
994
1078
> ,
995
1079
) {
996
1080
this . form = opts . form as never
@@ -1037,7 +1121,8 @@ export class FieldApi<
1037
1121
TFormOnBlur ,
1038
1122
TFormOnBlurAsync ,
1039
1123
TFormOnSubmit ,
1040
- TFormOnSubmitAsync
1124
+ TFormOnSubmitAsync ,
1125
+ TFieldMetaExtension
1041
1126
>
1042
1127
} ,
1043
1128
} )
@@ -1110,6 +1195,11 @@ export class FieldApi<
1110
1195
fieldApi : this ,
1111
1196
} )
1112
1197
1198
+ this . setMeta ( ( prev ) => ( {
1199
+ ...prev ,
1200
+ ...this . options . meta ?.( this . form . state ) ,
1201
+ } ) )
1202
+
1113
1203
return cleanup
1114
1204
}
1115
1205
@@ -1136,7 +1226,8 @@ export class FieldApi<
1136
1226
TFormOnSubmit ,
1137
1227
TFormOnSubmitAsync ,
1138
1228
TFormOnServer ,
1139
- TParentSubmitMeta
1229
+ TParentSubmitMeta ,
1230
+ TFieldMetaExtension
1140
1231
> ,
1141
1232
) => {
1142
1233
// Default Value
@@ -1183,6 +1274,11 @@ export class FieldApi<
1183
1274
fieldApi : this ,
1184
1275
} )
1185
1276
1277
+ this . setMeta ( ( prev ) => ( {
1278
+ ...prev ,
1279
+ ...this . options . meta ?.( this . form . state ) ,
1280
+ } ) )
1281
+
1186
1282
this . validate ( 'change' )
1187
1283
}
1188
1284
@@ -1210,7 +1306,8 @@ export class FieldApi<
1210
1306
TFormOnBlur ,
1211
1307
TFormOnBlurAsync ,
1212
1308
TFormOnSubmit ,
1213
- TFormOnSubmitAsync
1309
+ TFormOnSubmitAsync ,
1310
+ TFieldMetaExtension
1214
1311
>
1215
1312
> ,
1216
1313
) => this . form . setFieldMeta ( this . name , updater )
0 commit comments