Overview
Explore complete, production-ready form examples that demonstrate best practices and common use cases with Nuxt UI FormKit.
INFO
More examples are available in the playground of the repository.
Contact Form
A simple contact form with validation:
vue
<template>
<FormKit
type="form"
:actions="false"
@submit="handleSubmit"
>
<FormKit
type="nuxtUIInput"
name="name"
label="Full Name"
placeholder="John Doe"
validation="required"
/>
<FormKit
type="nuxtUIInput"
name="email"
label="Email Address"
input-type="email"
placeholder="john@example.com"
validation="required|email"
/>
<FormKit
type="nuxtUITextarea"
name="message"
label="Message"
placeholder="How can we help?"
validation="required|length:10"
:rows="4"
/>
<FormKit
type="nuxtUICheckbox"
name="subscribe"
label="Subscribe to our newsletter"
/>
<div class="flex gap-2">
<UButton type="submit" size="lg">
Send Message
</UButton>
<UButton type="reset" color="neutral" variant="outline" size="lg">
Clear
</UButton>
</div>
</FormKit>
</template>
<script setup lang="ts">
const handleSubmit = async (data: any) => {
await $fetch('/api/contact', {
method: 'POST',
body: data
})
}
</script>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
User Profile Form
Multi-section profile form with schema:
vue
<template>
<FUDataEdit
:data="profile"
:schema="profileSchema"
@data-saved="saveProfile"
/>
</template>
<script setup lang="ts">
const profile = ref({
// Personal Info
firstName: '',
lastName: '',
email: '',
phone: '',
birthDate: null,
// Address
street: '',
city: '',
country: '',
postalCode: '',
// Preferences
theme: 'light',
newsletter: false,
notifications: []
})
const profileSchema = [
{ $el: 'h3', children: 'Personal Information', attrs: { class: 'text-xl font-bold mb-4' } },
{
$formkit: 'nuxtUIInput',
name: 'firstName',
label: 'First Name',
validation: 'required'
},
{
$formkit: 'nuxtUIInput',
name: 'lastName',
label: 'Last Name',
validation: 'required'
},
{
$formkit: 'nuxtUIInput',
name: 'email',
inputType: 'email',
label: 'Email',
validation: 'required|email'
},
{
$formkit: 'nuxtUIInput',
name: 'phone',
inputType: 'tel',
label: 'Phone'
},
{
$formkit: 'nuxtUIInputDate',
name: 'birthDate',
label: 'Date of Birth'
},
{ $el: 'h3', children: 'Address', attrs: { class: 'text-xl font-bold mt-8 mb-4' } },
{
$formkit: 'nuxtUIInput',
name: 'street',
label: 'Street Address'
},
{
$formkit: 'nuxtUIInput',
name: 'city',
label: 'City'
},
{
$formkit: 'nuxtUISelect',
name: 'country',
label: 'Country',
options: ['USA', 'UK', 'Canada', 'Australia', 'Germany']
},
{
$formkit: 'nuxtUIInput',
name: 'postalCode',
label: 'Postal Code'
},
{ $el: 'h3', children: 'Preferences', attrs: { class: 'text-xl font-bold mt-8 mb-4' } },
{
$formkit: 'nuxtUIRadioGroup',
name: 'theme',
label: 'Color Theme',
options: [
{ label: 'Light', value: 'light' },
{ label: 'Dark', value: 'dark' },
{ label: 'System', value: 'system' }
]
},
{
$formkit: 'nuxtUISwitch',
name: 'newsletter',
label: 'Subscribe to newsletter'
},
{
$formkit: 'nuxtUICheckboxGroup',
name: 'notifications',
label: 'Notification Preferences',
options: [
{ label: 'Email notifications', value: 'email' },
{ label: 'Push notifications', value: 'push' },
{ label: 'SMS notifications', value: 'sms' }
]
}
]
const saveProfile = async (data: any) => {
await $fetch('/api/profile', {
method: 'PUT',
body: data
})
}
</script>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120