@@ -20,6 +20,7 @@ import type {
20
20
FieldInfo ,
21
21
FormApi ,
22
22
FormAsyncValidateOrFn ,
23
+ FormState ,
23
24
FormValidateAsyncFn ,
24
25
FormValidateFn ,
25
26
FormValidateOrFn ,
@@ -100,6 +101,7 @@ export type FieldValidateFn<
100
101
any ,
101
102
any ,
102
103
any ,
104
+ any ,
103
105
any
104
106
>
105
107
} ) => unknown
@@ -183,6 +185,7 @@ export type FieldValidateAsyncFn<
183
185
any ,
184
186
any ,
185
187
any ,
188
+ any ,
186
189
any
187
190
>
188
191
signal : AbortSignal
@@ -265,10 +268,39 @@ export type FieldListenerFn<
265
268
any ,
266
269
any ,
267
270
any ,
271
+ any ,
268
272
any
269
273
>
270
274
} ) => void
271
275
276
+ /**
277
+ * @private
278
+ */
279
+ export type FieldMetaFn <
280
+ TParentData ,
281
+ TFormOnMount extends undefined | FormValidateOrFn < TParentData > ,
282
+ TFormOnChange extends undefined | FormValidateOrFn < TParentData > ,
283
+ TFormOnChangeAsync extends undefined | FormAsyncValidateOrFn < TParentData > ,
284
+ TFormOnBlur extends undefined | FormValidateOrFn < TParentData > ,
285
+ TFormOnBlurAsync extends undefined | FormAsyncValidateOrFn < TParentData > ,
286
+ TFormOnSubmit extends undefined | FormValidateOrFn < TParentData > ,
287
+ TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn < TParentData > ,
288
+ TFormOnServer extends undefined | FormAsyncValidateOrFn < TParentData > ,
289
+ TFieldMetaExtension extends object ,
290
+ > = (
291
+ props : FormState <
292
+ TParentData ,
293
+ TFormOnMount ,
294
+ TFormOnChange ,
295
+ TFormOnChangeAsync ,
296
+ TFormOnBlur ,
297
+ TFormOnBlurAsync ,
298
+ TFormOnSubmit ,
299
+ TFormOnSubmitAsync ,
300
+ TFormOnServer
301
+ > ,
302
+ ) => TFieldMetaExtension
303
+
272
304
export interface FieldValidators <
273
305
TParentData ,
274
306
TName extends DeepKeys < TParentData > ,
@@ -383,6 +415,15 @@ export interface FieldOptions<
383
415
TOnSubmitAsync extends
384
416
| undefined
385
417
| FieldAsyncValidateOrFn < TParentData , TName , TData > ,
418
+ TFormOnMount extends undefined | FormValidateOrFn < TParentData > ,
419
+ TFormOnChange extends undefined | FormValidateOrFn < TParentData > ,
420
+ TFormOnChangeAsync extends undefined | FormAsyncValidateOrFn < TParentData > ,
421
+ TFormOnBlur extends undefined | FormValidateOrFn < TParentData > ,
422
+ TFormOnBlurAsync extends undefined | FormAsyncValidateOrFn < TParentData > ,
423
+ TFormOnSubmit extends undefined | FormValidateOrFn < TParentData > ,
424
+ TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn < TParentData > ,
425
+ TFormOnServer extends undefined | FormAsyncValidateOrFn < TParentData > ,
426
+ TFieldMetaExtension extends object ,
386
427
> {
387
428
/**
388
429
* The field name. The type will be `DeepKeys<TParentData>` to ensure your name is a deep key of the parent dataset.
@@ -436,13 +477,30 @@ export interface FieldOptions<
436
477
any ,
437
478
any ,
438
479
any ,
439
- any
480
+ any ,
481
+ TFieldMetaExtension
440
482
>
441
483
>
442
484
/**
443
485
* A list of listeners which attach to the corresponding events
444
486
*/
445
487
listeners ?: FieldListeners < TParentData , TName , TData >
488
+
489
+ /**
490
+ * A list of listeners which attach to the corresponding events
491
+ */
492
+ meta ?: FieldMetaFn <
493
+ TParentData ,
494
+ TFormOnMount ,
495
+ TFormOnChange ,
496
+ TFormOnChangeAsync ,
497
+ TFormOnBlur ,
498
+ TFormOnBlurAsync ,
499
+ TFormOnSubmit ,
500
+ TFormOnSubmitAsync ,
501
+ TFormOnServer ,
502
+ TFieldMetaExtension
503
+ >
446
504
/**
447
505
* 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.
448
506
*/
@@ -492,6 +550,7 @@ export interface FieldApiOptions<
492
550
| FormAsyncValidateOrFn < TParentData > ,
493
551
in out TFormOnServer extends undefined | FormAsyncValidateOrFn < TParentData > ,
494
552
in out TParentSubmitMeta ,
553
+ in out TFieldMetaExtension extends object ,
495
554
> extends FieldOptions <
496
555
TParentData ,
497
556
TName ,
@@ -502,7 +561,16 @@ export interface FieldApiOptions<
502
561
TOnBlur ,
503
562
TOnBlurAsync ,
504
563
TOnSubmit ,
505
- TOnSubmitAsync
564
+ TOnSubmitAsync ,
565
+ TFormOnMount ,
566
+ TFormOnChange ,
567
+ TFormOnChangeAsync ,
568
+ TFormOnBlur ,
569
+ TFormOnBlurAsync ,
570
+ TFormOnSubmit ,
571
+ TFormOnSubmitAsync ,
572
+ TFormOnServer ,
573
+ TFieldMetaExtension
506
574
> {
507
575
form : FormApi <
508
576
TParentData ,
@@ -542,6 +610,7 @@ export type FieldMetaBase<
542
610
TFormOnBlurAsync extends undefined | FormAsyncValidateOrFn < TParentData > ,
543
611
TFormOnSubmit extends undefined | FormValidateOrFn < TParentData > ,
544
612
TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn < TParentData > ,
613
+ TFieldMetaExtension extends object = { } ,
545
614
> = {
546
615
/**
547
616
* A flag indicating whether the field has been touched.
@@ -575,7 +644,7 @@ export type FieldMetaBase<
575
644
* A flag indicating whether the field is currently being validated.
576
645
*/
577
646
isValidating : boolean
578
- }
647
+ } & TFieldMetaExtension
579
648
580
649
export type AnyFieldMetaBase = FieldMetaBase <
581
650
any ,
@@ -594,6 +663,7 @@ export type AnyFieldMetaBase = FieldMetaBase<
594
663
any ,
595
664
any ,
596
665
any ,
666
+ any ,
597
667
any
598
668
>
599
669
@@ -621,6 +691,7 @@ export type FieldMetaDerived<
621
691
TFormOnBlurAsync extends undefined | FormAsyncValidateOrFn < TParentData > ,
622
692
TFormOnSubmit extends undefined | FormValidateOrFn < TParentData > ,
623
693
TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn < TParentData > ,
694
+ TFieldMetaExtension extends object = { } ,
624
695
> = {
625
696
/**
626
697
* An array of errors related to the field value.
@@ -660,7 +731,7 @@ export type FieldMetaDerived<
660
731
* A flag indicating whether the field's current value is the default value
661
732
*/
662
733
isDefaultValue : boolean
663
- }
734
+ } & TFieldMetaExtension
664
735
665
736
export type AnyFieldMetaDerived = FieldMetaDerived <
666
737
any ,
@@ -679,6 +750,7 @@ export type AnyFieldMetaDerived = FieldMetaDerived<
679
750
any ,
680
751
any ,
681
752
any ,
753
+ any ,
682
754
any
683
755
>
684
756
@@ -709,6 +781,7 @@ export type FieldMeta<
709
781
TFormOnBlurAsync extends undefined | FormAsyncValidateOrFn < TParentData > ,
710
782
TFormOnSubmit extends undefined | FormValidateOrFn < TParentData > ,
711
783
TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn < TParentData > ,
784
+ TFieldMetaExtension extends object = { } ,
712
785
> = FieldMetaBase <
713
786
TParentData ,
714
787
TName ,
@@ -726,7 +799,8 @@ export type FieldMeta<
726
799
TFormOnBlur ,
727
800
TFormOnBlurAsync ,
728
801
TFormOnSubmit ,
729
- TFormOnSubmitAsync
802
+ TFormOnSubmitAsync ,
803
+ TFieldMetaExtension
730
804
> &
731
805
FieldMetaDerived <
732
806
TParentData ,
@@ -745,7 +819,8 @@ export type FieldMeta<
745
819
TFormOnBlur ,
746
820
TFormOnBlurAsync ,
747
821
TFormOnSubmit ,
748
- TFormOnSubmitAsync
822
+ TFormOnSubmitAsync ,
823
+ TFieldMetaExtension
749
824
>
750
825
751
826
export type AnyFieldMeta = FieldMeta <
@@ -765,6 +840,7 @@ export type AnyFieldMeta = FieldMeta<
765
840
any ,
766
841
any ,
767
842
any ,
843
+ any ,
768
844
any
769
845
>
770
846
@@ -795,6 +871,7 @@ export type FieldState<
795
871
TFormOnBlurAsync extends undefined | FormAsyncValidateOrFn < TParentData > ,
796
872
TFormOnSubmit extends undefined | FormValidateOrFn < TParentData > ,
797
873
TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn < TParentData > ,
874
+ TFieldMetaExtension extends object ,
798
875
> = {
799
876
/**
800
877
* The current value of the field.
@@ -820,7 +897,8 @@ export type FieldState<
820
897
TFormOnBlur ,
821
898
TFormOnBlurAsync ,
822
899
TFormOnSubmit ,
823
- TFormOnSubmitAsync
900
+ TFormOnSubmitAsync ,
901
+ TFieldMetaExtension
824
902
>
825
903
}
826
904
@@ -848,6 +926,7 @@ export type AnyFieldApi = FieldApi<
848
926
any ,
849
927
any ,
850
928
any ,
929
+ any ,
851
930
any
852
931
>
853
932
@@ -900,6 +979,7 @@ export class FieldApi<
900
979
| FormAsyncValidateOrFn < TParentData > ,
901
980
in out TFormOnServer extends undefined | FormAsyncValidateOrFn < TParentData > ,
902
981
in out TParentSubmitMeta ,
982
+ in out TFieldMetaExtension extends object ,
903
983
> {
904
984
/**
905
985
* A reference to the form API instance.
@@ -923,7 +1003,8 @@ export class FieldApi<
923
1003
TFormOnSubmit ,
924
1004
TFormOnSubmitAsync ,
925
1005
TFormOnServer ,
926
- TParentSubmitMeta
1006
+ TParentSubmitMeta ,
1007
+ TFieldMetaExtension
927
1008
> [ 'form' ]
928
1009
/**
929
1010
* The field name.
@@ -951,7 +1032,8 @@ export class FieldApi<
951
1032
TFormOnSubmit ,
952
1033
TFormOnSubmitAsync ,
953
1034
TFormOnServer ,
954
- TParentSubmitMeta
1035
+ TParentSubmitMeta ,
1036
+ TFieldMetaExtension
955
1037
> = { } as any
956
1038
/**
957
1039
* The field state store.
@@ -974,7 +1056,8 @@ export class FieldApi<
974
1056
TFormOnBlur ,
975
1057
TFormOnBlurAsync ,
976
1058
TFormOnSubmit ,
977
- TFormOnSubmitAsync
1059
+ TFormOnSubmitAsync ,
1060
+ TFieldMetaExtension
978
1061
>
979
1062
>
980
1063
/**
@@ -1012,7 +1095,8 @@ export class FieldApi<
1012
1095
TFormOnSubmit ,
1013
1096
TFormOnSubmitAsync ,
1014
1097
TFormOnServer ,
1015
- TParentSubmitMeta
1098
+ TParentSubmitMeta ,
1099
+ TFieldMetaExtension
1016
1100
> ,
1017
1101
) {
1018
1102
this . form = opts . form as never
@@ -1052,7 +1136,8 @@ export class FieldApi<
1052
1136
TFormOnBlur ,
1053
1137
TFormOnBlurAsync ,
1054
1138
TFormOnSubmit ,
1055
- TFormOnSubmitAsync
1139
+ TFormOnSubmitAsync ,
1140
+ TFieldMetaExtension
1056
1141
>
1057
1142
} ,
1058
1143
} )
@@ -1136,6 +1221,11 @@ export class FieldApi<
1136
1221
fieldApi : this ,
1137
1222
} )
1138
1223
1224
+ this . setMeta ( ( prev ) => ( {
1225
+ ...prev ,
1226
+ ...this . options . meta ?.( this . form . state ) ,
1227
+ } ) )
1228
+
1139
1229
return cleanup
1140
1230
}
1141
1231
@@ -1162,7 +1252,8 @@ export class FieldApi<
1162
1252
TFormOnSubmit ,
1163
1253
TFormOnSubmitAsync ,
1164
1254
TFormOnServer ,
1165
- TParentSubmitMeta
1255
+ TParentSubmitMeta ,
1256
+ TFieldMetaExtension
1166
1257
> ,
1167
1258
) => {
1168
1259
this . options = opts as never
@@ -1211,6 +1302,11 @@ export class FieldApi<
1211
1302
1212
1303
this . triggerOnChangeListener ( )
1213
1304
1305
+ this . setMeta ( ( prev ) => ( {
1306
+ ...prev ,
1307
+ ...this . options . meta ?.( this . form . state ) ,
1308
+ } ) )
1309
+
1214
1310
this . validate ( 'change' )
1215
1311
}
1216
1312
@@ -1238,7 +1334,8 @@ export class FieldApi<
1238
1334
TFormOnBlur ,
1239
1335
TFormOnBlurAsync ,
1240
1336
TFormOnSubmit ,
1241
- TFormOnSubmitAsync
1337
+ TFormOnSubmitAsync ,
1338
+ TFieldMetaExtension
1242
1339
>
1243
1340
> ,
1244
1341
) => this . form . setFieldMeta ( this . name , updater )
0 commit comments