@tanstack/angular-form 0.23.1 → 0.23.3
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/package.json +23 -28
- package/src/test-setup.ts +0 -13
- package/src/tests/test.component.spec.ts +0 -358
- package/src/tests/utils.ts +0 -5
- /package/{build → dist}/README.md +0 -0
- /package/{build → dist}/esm2022/index.mjs +0 -0
- /package/{build → dist}/esm2022/inject-form.mjs +0 -0
- /package/{build → dist}/esm2022/inject-store.mjs +0 -0
- /package/{build → dist}/esm2022/tanstack-angular-form.mjs +0 -0
- /package/{build → dist}/esm2022/tanstack-field.directive.mjs +0 -0
- /package/{build → dist}/fesm2022/tanstack-angular-form.mjs +0 -0
- /package/{build → dist}/fesm2022/tanstack-angular-form.mjs.map +0 -0
- /package/{build → dist}/index.d.ts +0 -0
- /package/{build → dist}/inject-form.d.ts +0 -0
- /package/{build → dist}/inject-store.d.ts +0 -0
- /package/{build → dist}/tanstack-field.directive.d.ts +0 -0
package/package.json
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/angular-form",
|
|
3
|
-
"version": "0.23.
|
|
3
|
+
"version": "0.23.3",
|
|
4
4
|
"description": "Powerful, type-safe forms for Angular.",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"repository":
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/TanStack/form.git",
|
|
10
|
+
"directory": "packages/angular-form"
|
|
11
|
+
},
|
|
8
12
|
"homepage": "https://tanstack.com/form",
|
|
9
13
|
"funding": {
|
|
10
14
|
"type": "github",
|
|
@@ -12,19 +16,28 @@
|
|
|
12
16
|
},
|
|
13
17
|
"sideEffects": false,
|
|
14
18
|
"files": [
|
|
15
|
-
"
|
|
19
|
+
"dist",
|
|
16
20
|
"src"
|
|
17
21
|
],
|
|
18
22
|
"type": "module",
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
"types": "dist/index.d.ts",
|
|
24
|
+
"module": "dist/fesm2022/tanstack-angular-form.mjs",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"esm2022": "./dist/esm2022/tanstack-angular-form.mjs",
|
|
29
|
+
"esm": "./dist/esm2022/tanstack-angular-form.mjs",
|
|
30
|
+
"default": "./dist/fesm2022/tanstack-angular-form.mjs"
|
|
31
|
+
},
|
|
32
|
+
"./package.json": {
|
|
33
|
+
"default": "./package.json"
|
|
26
34
|
}
|
|
27
35
|
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@tanstack/angular-store": "^0.5.1",
|
|
38
|
+
"tslib": "^2.3.0",
|
|
39
|
+
"@tanstack/form-core": "0.23.3"
|
|
40
|
+
},
|
|
28
41
|
"devDependencies": {
|
|
29
42
|
"@analogjs/vite-plugin-angular": "^1.0.0",
|
|
30
43
|
"@angular/common": "^17.3.0",
|
|
@@ -38,26 +51,8 @@
|
|
|
38
51
|
"typescript": "5.4.2",
|
|
39
52
|
"zone.js": "~0.14.2"
|
|
40
53
|
},
|
|
41
|
-
"dependencies": {
|
|
42
|
-
"@tanstack/angular-store": "^0.4.1",
|
|
43
|
-
"tslib": "^2.3.0",
|
|
44
|
-
"@tanstack/form-core": "0.23.1"
|
|
45
|
-
},
|
|
46
54
|
"peerDependencies": {
|
|
47
55
|
"@angular/core": ">=17.3.0"
|
|
48
56
|
},
|
|
49
|
-
"module": "build/fesm2022/tanstack-angular-form.mjs",
|
|
50
|
-
"types": "build/index.d.ts",
|
|
51
|
-
"exports": {
|
|
52
|
-
"./package.json": {
|
|
53
|
-
"default": "./package.json"
|
|
54
|
-
},
|
|
55
|
-
".": {
|
|
56
|
-
"types": "./build/index.d.ts",
|
|
57
|
-
"esm2022": "./build/esm2022/tanstack-angular-form.mjs",
|
|
58
|
-
"esm": "./build/esm2022/tanstack-angular-form.mjs",
|
|
59
|
-
"default": "./build/fesm2022/tanstack-angular-form.mjs"
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
57
|
"scripts": {}
|
|
63
58
|
}
|
package/src/test-setup.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import '@analogjs/vite-plugin-angular/setup-vitest'
|
|
2
|
-
import '@testing-library/jest-dom/vitest'
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
BrowserDynamicTestingModule,
|
|
6
|
-
platformBrowserDynamicTesting,
|
|
7
|
-
} from '@angular/platform-browser-dynamic/testing'
|
|
8
|
-
import { getTestBed } from '@angular/core/testing'
|
|
9
|
-
|
|
10
|
-
getTestBed().initTestEnvironment(
|
|
11
|
-
BrowserDynamicTestingModule,
|
|
12
|
-
platformBrowserDynamicTesting(),
|
|
13
|
-
)
|
|
@@ -1,358 +0,0 @@
|
|
|
1
|
-
import { render } from '@testing-library/angular'
|
|
2
|
-
import { Component } from '@angular/core'
|
|
3
|
-
import { describe, expect, it } from 'vitest'
|
|
4
|
-
import { userEvent } from '@testing-library/user-event'
|
|
5
|
-
import { injectForm } from '../inject-form'
|
|
6
|
-
import { TanStackField } from '../tanstack-field.directive'
|
|
7
|
-
import { sleep } from './utils'
|
|
8
|
-
import type { FieldValidateAsyncFn, FieldValidateFn } from '@tanstack/form-core'
|
|
9
|
-
|
|
10
|
-
const user = userEvent.setup()
|
|
11
|
-
|
|
12
|
-
describe('TanStackFieldDirective', () => {
|
|
13
|
-
it('should allow to set default value', async () => {
|
|
14
|
-
@Component({
|
|
15
|
-
selector: 'test-component',
|
|
16
|
-
standalone: true,
|
|
17
|
-
template: `
|
|
18
|
-
<ng-container [tanstackField]="form" name="firstName" #f="field">
|
|
19
|
-
<input
|
|
20
|
-
data-testid="fieldinput"
|
|
21
|
-
[value]="f.api.state.value"
|
|
22
|
-
(blur)="f.api.handleBlur()"
|
|
23
|
-
(input)="f.api.handleChange($any($event).target.value)"
|
|
24
|
-
/>
|
|
25
|
-
</ng-container>
|
|
26
|
-
`,
|
|
27
|
-
imports: [TanStackField],
|
|
28
|
-
})
|
|
29
|
-
class TestComponent {
|
|
30
|
-
form = injectForm({
|
|
31
|
-
defaultValues: {
|
|
32
|
-
firstName: 'FirstName',
|
|
33
|
-
lastName: 'LastName',
|
|
34
|
-
},
|
|
35
|
-
})
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const { getByTestId } = await render(TestComponent)
|
|
39
|
-
|
|
40
|
-
const input = getByTestId('fieldinput')
|
|
41
|
-
expect(input).toHaveValue('FirstName')
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
it('should use field default value first', async () => {
|
|
45
|
-
type Person = {
|
|
46
|
-
firstName: string
|
|
47
|
-
lastName: string
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
@Component({
|
|
51
|
-
selector: 'test-component',
|
|
52
|
-
standalone: true,
|
|
53
|
-
template: `
|
|
54
|
-
<ng-container
|
|
55
|
-
[tanstackField]="form"
|
|
56
|
-
name="firstName"
|
|
57
|
-
defaultValue="otherName"
|
|
58
|
-
#f="field"
|
|
59
|
-
>
|
|
60
|
-
<input
|
|
61
|
-
data-testid="fieldinput"
|
|
62
|
-
[value]="f.api.state.value"
|
|
63
|
-
(blur)="f.api.handleBlur()"
|
|
64
|
-
(input)="f.api.handleChange($any($event).target.value)"
|
|
65
|
-
/>
|
|
66
|
-
</ng-container>
|
|
67
|
-
`,
|
|
68
|
-
imports: [TanStackField],
|
|
69
|
-
})
|
|
70
|
-
class TestComponent {
|
|
71
|
-
form = injectForm<Person>({
|
|
72
|
-
defaultValues: {
|
|
73
|
-
firstName: 'FirstName',
|
|
74
|
-
lastName: 'LastName',
|
|
75
|
-
},
|
|
76
|
-
})
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const { getByTestId } = await render(TestComponent)
|
|
80
|
-
|
|
81
|
-
const input = getByTestId('fieldinput')
|
|
82
|
-
expect(input).toHaveValue('otherName')
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
it('should not validate on change if isTouched is false', async () => {
|
|
86
|
-
type Person = {
|
|
87
|
-
firstName: string
|
|
88
|
-
lastName: string
|
|
89
|
-
}
|
|
90
|
-
const error = 'Please enter a different value'
|
|
91
|
-
|
|
92
|
-
@Component({
|
|
93
|
-
selector: 'test-component',
|
|
94
|
-
standalone: true,
|
|
95
|
-
template: `
|
|
96
|
-
<ng-container
|
|
97
|
-
[tanstackField]="form"
|
|
98
|
-
name="firstName"
|
|
99
|
-
[validators]="{ onChange: otherValidator }"
|
|
100
|
-
#f="field"
|
|
101
|
-
>
|
|
102
|
-
<input
|
|
103
|
-
data-testid="fieldinput"
|
|
104
|
-
[value]="f.api.state.value"
|
|
105
|
-
(blur)="f.api.handleBlur()"
|
|
106
|
-
(input)="f.api.setValue($any($event).target.value)"
|
|
107
|
-
/>
|
|
108
|
-
@for (error of f.api.getMeta().errors; track error) {
|
|
109
|
-
<p>{{ error }}</p>
|
|
110
|
-
}
|
|
111
|
-
</ng-container>
|
|
112
|
-
`,
|
|
113
|
-
imports: [TanStackField],
|
|
114
|
-
})
|
|
115
|
-
class TestComponent {
|
|
116
|
-
otherValidator: FieldValidateFn<Person, 'firstName'> = ({ value }) =>
|
|
117
|
-
value === 'other' ? error : undefined
|
|
118
|
-
|
|
119
|
-
form = injectForm<Person>({
|
|
120
|
-
defaultValues: {
|
|
121
|
-
firstName: 'FirstName',
|
|
122
|
-
lastName: 'LastName',
|
|
123
|
-
},
|
|
124
|
-
})
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const { getByTestId, queryByText } = await render(TestComponent)
|
|
128
|
-
const input = getByTestId('fieldinput')
|
|
129
|
-
await user.type(input, 'other')
|
|
130
|
-
expect(queryByText(error)).not.toBeInTheDocument()
|
|
131
|
-
})
|
|
132
|
-
|
|
133
|
-
it('should validate on change if isTouched is true', async () => {
|
|
134
|
-
type Person = {
|
|
135
|
-
firstName: string
|
|
136
|
-
lastName: string
|
|
137
|
-
}
|
|
138
|
-
const error = 'Please enter a different value'
|
|
139
|
-
|
|
140
|
-
@Component({
|
|
141
|
-
selector: 'test-component',
|
|
142
|
-
standalone: true,
|
|
143
|
-
template: `
|
|
144
|
-
<ng-container
|
|
145
|
-
[tanstackField]="form"
|
|
146
|
-
name="firstName"
|
|
147
|
-
[defaultMeta]="{ isTouched: true }"
|
|
148
|
-
[validators]="{ onChange: otherValidator }"
|
|
149
|
-
#f="field"
|
|
150
|
-
>
|
|
151
|
-
<input
|
|
152
|
-
data-testid="fieldinput"
|
|
153
|
-
[value]="f.api.state.value"
|
|
154
|
-
(blur)="f.api.handleBlur()"
|
|
155
|
-
(input)="f.api.handleChange($any($event).target.value)"
|
|
156
|
-
/>
|
|
157
|
-
<p>{{ f.api.getMeta().errorMap?.onChange }}</p>
|
|
158
|
-
</ng-container>
|
|
159
|
-
`,
|
|
160
|
-
imports: [TanStackField],
|
|
161
|
-
})
|
|
162
|
-
class TestComponent {
|
|
163
|
-
otherValidator: FieldValidateFn<Person, 'firstName'> = ({ value }) =>
|
|
164
|
-
value === 'other' ? error : undefined
|
|
165
|
-
|
|
166
|
-
form = injectForm<Person>({
|
|
167
|
-
defaultValues: {
|
|
168
|
-
firstName: '',
|
|
169
|
-
lastName: '',
|
|
170
|
-
},
|
|
171
|
-
})
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
const { getByTestId, queryByText, getByText } = await render(TestComponent)
|
|
175
|
-
|
|
176
|
-
const input = getByTestId('fieldinput')
|
|
177
|
-
expect(queryByText(error)).not.toBeInTheDocument()
|
|
178
|
-
await user.type(input, 'other')
|
|
179
|
-
expect(getByText(error)).toBeInTheDocument()
|
|
180
|
-
})
|
|
181
|
-
|
|
182
|
-
it('should validate on change and on blur', async () => {
|
|
183
|
-
type Person = {
|
|
184
|
-
firstName: string
|
|
185
|
-
lastName: string
|
|
186
|
-
}
|
|
187
|
-
const onChangeError = 'Please enter a different value (onChangeError)'
|
|
188
|
-
const onBlurError = 'Please enter a different value (onBlurError)'
|
|
189
|
-
|
|
190
|
-
@Component({
|
|
191
|
-
selector: 'test-component',
|
|
192
|
-
standalone: true,
|
|
193
|
-
template: `
|
|
194
|
-
<ng-container
|
|
195
|
-
[tanstackField]="form"
|
|
196
|
-
name="firstName"
|
|
197
|
-
[defaultMeta]="{ isTouched: true }"
|
|
198
|
-
[validators]="{ onChange: onChange, onBlur: onBlur }"
|
|
199
|
-
#f="field"
|
|
200
|
-
>
|
|
201
|
-
<input
|
|
202
|
-
data-testid="fieldinput"
|
|
203
|
-
[value]="f.api.state.value"
|
|
204
|
-
[name]="f.api.name"
|
|
205
|
-
(blur)="f.api.handleBlur()"
|
|
206
|
-
(input)="f.api.setValue($any($event).target.value)"
|
|
207
|
-
/>
|
|
208
|
-
<p>{{ f.api.getMeta().errorMap?.onChange }}</p>
|
|
209
|
-
<p>{{ f.api.getMeta().errorMap?.onBlur }}</p>
|
|
210
|
-
</ng-container>
|
|
211
|
-
`,
|
|
212
|
-
imports: [TanStackField],
|
|
213
|
-
})
|
|
214
|
-
class TestComponent {
|
|
215
|
-
onChange: FieldValidateFn<Person, 'firstName'> = ({ value }) =>
|
|
216
|
-
value === 'other' ? onChangeError : undefined
|
|
217
|
-
onBlur: FieldValidateFn<Person, 'firstName'> = ({ value }) =>
|
|
218
|
-
value === 'other' ? onBlurError : undefined
|
|
219
|
-
|
|
220
|
-
form = injectForm<Person>({
|
|
221
|
-
defaultValues: {
|
|
222
|
-
firstName: '',
|
|
223
|
-
lastName: '',
|
|
224
|
-
},
|
|
225
|
-
})
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
const { getByTestId, getByText, queryByText } = await render(TestComponent)
|
|
229
|
-
const input = getByTestId('fieldinput')
|
|
230
|
-
expect(queryByText(onChangeError)).not.toBeInTheDocument()
|
|
231
|
-
expect(queryByText(onBlurError)).not.toBeInTheDocument()
|
|
232
|
-
await user.type(input, 'other')
|
|
233
|
-
expect(getByText(onChangeError)).toBeInTheDocument()
|
|
234
|
-
await user.click(document.body)
|
|
235
|
-
expect(queryByText(onBlurError)).toBeInTheDocument()
|
|
236
|
-
})
|
|
237
|
-
|
|
238
|
-
it('should validate async on change', async () => {
|
|
239
|
-
type Person = {
|
|
240
|
-
firstName: string
|
|
241
|
-
lastName: string
|
|
242
|
-
}
|
|
243
|
-
const error = 'Please enter a different value'
|
|
244
|
-
|
|
245
|
-
@Component({
|
|
246
|
-
selector: 'test-component',
|
|
247
|
-
standalone: true,
|
|
248
|
-
template: `
|
|
249
|
-
<ng-container
|
|
250
|
-
[tanstackField]="form"
|
|
251
|
-
name="firstName"
|
|
252
|
-
[defaultMeta]="{ isTouched: true }"
|
|
253
|
-
[validators]="{ onChangeAsync: onChangeAsync }"
|
|
254
|
-
#f="field"
|
|
255
|
-
>
|
|
256
|
-
<input
|
|
257
|
-
data-testid="fieldinput"
|
|
258
|
-
[name]="f.api.name"
|
|
259
|
-
[value]="f.api.state.value"
|
|
260
|
-
(blur)="f.api.handleBlur()"
|
|
261
|
-
(input)="f.api.handleChange($any($event).target.value)"
|
|
262
|
-
/>
|
|
263
|
-
<p>{{ f.api.getMeta().errorMap?.onChange }}</p>
|
|
264
|
-
</ng-container>
|
|
265
|
-
`,
|
|
266
|
-
imports: [TanStackField],
|
|
267
|
-
})
|
|
268
|
-
class TestComponent {
|
|
269
|
-
onChangeAsync: FieldValidateAsyncFn<Person, 'firstName'> = async () => {
|
|
270
|
-
await sleep(10)
|
|
271
|
-
return error
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
form = injectForm<Person>({
|
|
275
|
-
defaultValues: {
|
|
276
|
-
firstName: '',
|
|
277
|
-
lastName: '',
|
|
278
|
-
},
|
|
279
|
-
})
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
const { getByTestId, getByText, findByText, queryByText } =
|
|
283
|
-
await render(TestComponent)
|
|
284
|
-
const input = getByTestId('fieldinput')
|
|
285
|
-
expect(queryByText(error)).not.toBeInTheDocument()
|
|
286
|
-
await user.type(input, 'other')
|
|
287
|
-
await findByText(error)
|
|
288
|
-
expect(getByText(error)).toBeInTheDocument()
|
|
289
|
-
})
|
|
290
|
-
|
|
291
|
-
it('should validate async on change and async on blur', async () => {
|
|
292
|
-
type Person = {
|
|
293
|
-
firstName: string
|
|
294
|
-
lastName: string
|
|
295
|
-
}
|
|
296
|
-
const onChangeError = 'Please enter a different value (onChangeError)'
|
|
297
|
-
const onBlurError = 'Please enter a different value (onBlurError)'
|
|
298
|
-
|
|
299
|
-
@Component({
|
|
300
|
-
selector: 'test-component',
|
|
301
|
-
standalone: true,
|
|
302
|
-
template: `
|
|
303
|
-
<ng-container
|
|
304
|
-
[tanstackField]="form"
|
|
305
|
-
name="firstName"
|
|
306
|
-
[defaultMeta]="{ isTouched: true }"
|
|
307
|
-
[validators]="{
|
|
308
|
-
onChangeAsync: onChangeAsync,
|
|
309
|
-
onBlurAsync: onBlurAsync
|
|
310
|
-
}"
|
|
311
|
-
#f="field"
|
|
312
|
-
>
|
|
313
|
-
<input
|
|
314
|
-
data-testid="fieldinput"
|
|
315
|
-
[name]="f.api.name"
|
|
316
|
-
[value]="f.api.state.value"
|
|
317
|
-
(blur)="f.api.handleBlur()"
|
|
318
|
-
(input)="f.api.handleChange($any($event).target.value)"
|
|
319
|
-
/>
|
|
320
|
-
<p>{{ f.api.getMeta().errorMap?.onChange }}</p>
|
|
321
|
-
<p>{{ f.api.getMeta().errorMap?.onBlur }}</p>
|
|
322
|
-
</ng-container>
|
|
323
|
-
`,
|
|
324
|
-
imports: [TanStackField],
|
|
325
|
-
})
|
|
326
|
-
class TestComponent {
|
|
327
|
-
onChangeAsync: FieldValidateAsyncFn<Person, 'firstName'> = async () => {
|
|
328
|
-
await sleep(10)
|
|
329
|
-
return onChangeError
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
onBlurAsync: FieldValidateAsyncFn<Person, 'firstName'> = async () => {
|
|
333
|
-
await sleep(10)
|
|
334
|
-
return onBlurError
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
form = injectForm<Person>({
|
|
338
|
-
defaultValues: {
|
|
339
|
-
firstName: '',
|
|
340
|
-
lastName: '',
|
|
341
|
-
},
|
|
342
|
-
})
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
const { getByTestId, getByText, findByText, queryByText } =
|
|
346
|
-
await render(TestComponent)
|
|
347
|
-
const input = getByTestId('fieldinput')
|
|
348
|
-
|
|
349
|
-
expect(queryByText(onChangeError)).not.toBeInTheDocument()
|
|
350
|
-
expect(queryByText(onBlurError)).not.toBeInTheDocument()
|
|
351
|
-
await user.type(input, 'other')
|
|
352
|
-
await findByText(onChangeError)
|
|
353
|
-
expect(getByText(onChangeError)).toBeInTheDocument()
|
|
354
|
-
await user.click(document.body)
|
|
355
|
-
await findByText(onBlurError)
|
|
356
|
-
expect(getByText(onBlurError)).toBeInTheDocument()
|
|
357
|
-
})
|
|
358
|
-
})
|
package/src/tests/utils.ts
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|