Skip to content
Source
Sign inSign up
TanStack/form
Open History to see the last commit

FieldGroupHelper.md

166 lines3.1 KB

1---
2id: FieldGroupHelper
3title: FieldGroupHelper
4---
5​
6Defined in: [FieldGroup/fieldGroupTypes.public.ts:259](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldGroup/fieldGroupTypes.public.ts#L259)
7​
8Declares the virtual fields in a reusable field group and how their value
9types may bind to concrete form fields.
10​
11## Example
12​
13```ts
14const profileFields = defineFieldGroup(({ strict, loose }) => ({
15 name: strict(''),
16 status: loose<string>(),
17}))
18```
19​
20## Properties
21​
22### loose
23​
24```ts
25loose: {
26<TValue> (value): LooseFieldGroupFieldSlot<TValue>;
27<TValue> (): LooseFieldGroupFieldSlot<TValue>;
28};
29```
30​
31Defined in: [FieldGroup/fieldGroupTypes.public.ts:298](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldGroup/fieldGroupTypes.public.ts#L298)
32​
33Declares a virtual field that can bind to form fields whose value type is
34assignable to the declared type.
35​
36#### Call Signature
37​
38```ts
39<TValue>(value): LooseFieldGroupFieldSlot<TValue>;
40```
41​
42##### Type Parameters
43​
44###### TValue
45​
46`TValue`
47​
48Inferred from the representative value.
49​
50##### Parameters
51​
52###### value
53​
54`TValue`
55​
56A representative value used only for type inference.
57​
58##### Returns
59​
60[`LooseFieldGroupFieldSlot`](../type-aliases/LooseFieldGroupFieldSlot.md)\<`TValue`\>
61​
62A field slot that uses assignable value-type matching.
63​
64#### Call Signature
65​
66```ts
67<TValue>(): LooseFieldGroupFieldSlot<TValue>;
68```
69​
70##### Type Parameters
71​
72###### TValue
73​
74`TValue`
75​
76The value type that compatible concrete field values
77must be assignable to.
78​
79##### Returns
80​
81[`LooseFieldGroupFieldSlot`](../type-aliases/LooseFieldGroupFieldSlot.md)\<`TValue`\>
82​
83A field slot that uses assignable value-type matching.
84​
85#### Example
86​
87```tsx
88const passwordFieldGroup = defineFieldGroup(({ loose }) => ({
89 password: loose<string>(),
90 confirmPassword: loose<string>(),
91}))
92```
93​
94***
95​
96### strict
97​
98```ts
99strict: {
100<TValue> (value): StrictFieldGroupFieldSlot<TValue>;
101<TValue> (): StrictFieldGroupFieldSlot<TValue>;
102};
103```
104​
105Defined in: [FieldGroup/fieldGroupTypes.public.ts:272](https://github.com/TanStack/form/blob/main/packages/form-core/src/FieldGroup/fieldGroupTypes.public.ts#L272)
106​
107Declares a virtual field whose value type must exactly match the value type
108of the concrete form field it binds to.
109​
110#### Call Signature
111​
112```ts
113<TValue>(value): StrictFieldGroupFieldSlot<TValue>;
114```
115​
116##### Type Parameters
117​
118###### TValue
119​
120`TValue`
121​
122Inferred from the representative value.
123​
124##### Parameters
125​
126###### value
127​
128`TValue`
129​
130A representative value used only for type inference.
131​
132##### Returns
133​
134[`StrictFieldGroupFieldSlot`](../type-aliases/StrictFieldGroupFieldSlot.md)\<`TValue`\>
135​
136A field slot that uses strict value-type matching.
137​
138#### Call Signature
139​
140```ts
141<TValue>(): StrictFieldGroupFieldSlot<TValue>;
142```
143​
144##### Type Parameters
145​
146###### TValue
147​
148`TValue`
149​
150The value type the concrete form field must match
151exactly.
152​
153##### Returns
154​
155[`StrictFieldGroupFieldSlot`](../type-aliases/StrictFieldGroupFieldSlot.md)\<`TValue`\>
156​
157A field slot that uses strict value-type matching.
158​
159#### Example
160​
161```tsx
162const passwordFieldGroup = defineFieldGroup(({ strict }) => ({
163 password: strict<string>(),
164 confirmPassword: strict<string>(),
165}))
166```