Skip to content

Commit d7aaeda

Browse files
committed
feat(validation): add repeater example
1 parent b55b7a8 commit d7aaeda

File tree

3 files changed

+124
-39
lines changed

3 files changed

+124
-39
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vite-primevue-starter",
3-
"version": "1.7.4",
3+
"version": "1.7.5",
44
"license": "MIT",
55
"type": "module",
66
"scripts": {

src/pages/elements/validation.vue

Lines changed: 121 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,101 @@
11
<script setup lang='ts'>
2-
import { ref } from 'vue'
2+
import { FormKitSchema } from '@formkit/vue'
3+
import { reactive, ref } from 'vue'
4+
import { useFormKitSchema } from '@sfxcode/formkit-primevue/composables'
5+
6+
const { addElement, addList, addListGroup, addComponent, addListGroupFunctions } = useFormKitSchema()
7+
function addFlexElement(children: any[]) {
8+
return addElement('div', children, { class: 'min-w-50rem flex gap-4' })
9+
}
10+
11+
function addGroupButtons() {
12+
const addButtonComponent = (onClick: string = '', label: string = '', icon: string = '', severity: string = '', render: string = 'true', styleClass: string = 'p-button-sm ml-2'): object => {
13+
return addComponent('Button', { onClick, label, icon, class: styleClass, severity }, render)
14+
}
15+
16+
return addElement('div', [
17+
addButtonComponent('$removeNode($node, $index)', '', 'pi pi-times', 'danger'),
18+
addButtonComponent('$copyNode($node, $index)', '', 'pi pi-plus'),
19+
addButtonComponent('$moveNodeUp($node, $index)', '', 'pi pi-arrow-up', 'secondary', '$index != 0'),
20+
addElement('span', [], { class: 'ml-2 mr-10' }, '$index == 0'),
21+
addButtonComponent('$moveNodeDown($node, $index)', '', 'pi pi-arrow-down', 'secondary', '$index < $node.value.length -1'),
22+
addElement('span', [], { class: 'ml-2 mr-10' }, '$index == $node.value.length -1'),
23+
], { class: 'pt-6' })
24+
}
325
426
const options = [
527
{ label: 'Every page load', value: 'refresh' },
628
{ label: 'Ever hour', value: 'hourly' },
729
{ label: 'Every day', value: 'daily' },
830
]
931
32+
const data = ref()
33+
34+
onMounted(() => {
35+
const defaultData = { email: '[email protected]', additionalMails: [{ email: '[email protected]' }, { email: '[email protected]' }], myCalendar: new Date() }
36+
addListGroupFunctions(defaultData, { email: '[email protected]' })
37+
data.value = defaultData
38+
})
39+
1040
const schema = reactive(
1141
[
12-
{
13-
$el: 'h2',
14-
children: ['Register ', '$email'],
15-
},
16-
{
17-
$el: 'h3',
18-
children: 'Header Text H3',
19-
},
42+
addElement('h2', ['Validation with FormKit']),
43+
addElement('h3', ['Inputs from PrimeVue']),
2044
{
2145
$formkit: 'primeInputText',
2246
name: 'email',
2347
label: 'Email',
2448
help: 'This will be used for your account.',
2549
validation: 'required|email',
50+
2651
},
52+
addList('additionalMails', [
53+
addFlexElement([
54+
addElement('div', ['Additional Mails'], { class: 'text-xl mb-2' }),
55+
addComponent('Button', { onClick: '$addNode($node)', label: 'Add', class: 'p-button-sm', icon: 'pi pi-plus' }, '$node.value.length == 0'),
56+
]),
57+
addListGroup(
58+
[
59+
addFlexElement([
60+
{
61+
$formkit: 'primeInputText',
62+
label: 'Additional Mail',
63+
name: 'email',
64+
},
65+
addGroupButtons(),
66+
]),
67+
],
68+
),
69+
], true, 'true'),
70+
2771
{
2872
$formkit: 'primeTextarea',
2973
name: 'myText',
3074
label: 'Text',
31-
validation: '',
32-
rows: '3',
75+
rows: '5',
3376
},
3477
{
35-
$formkit: 'primeEditor',
36-
name: 'myEditor',
37-
label: 'Editor',
38-
style: 'height: 160px;',
78+
$formkit: 'primeCalendar',
79+
name: 'myCalendar',
80+
label: 'Calendar',
81+
validation: '',
82+
showIcon: true,
83+
3984
},
4085
{
41-
$formkit: 'primeInputText',
86+
$formkit: 'primePassword',
4287
name: 'password',
4388
label: 'Password',
4489
help: 'Enter your new password.',
4590
validation: 'required|length:5,16',
4691
},
4792
{
48-
$formkit: 'primeInputText',
93+
$formkit: 'primePassword',
4994
name: 'password_confirm',
5095
label: 'Confirm password',
51-
help: 'Enter your new password again.',
96+
toggleMask: true,
97+
feedback: false,
98+
help: 'Enter your new password again to confirm it.',
5299
validation: 'required|confirm',
53100
validationLabel: 'password confirmation',
54101
},
@@ -57,44 +104,82 @@ const schema = reactive(
57104
name: 'eu_citizen',
58105
id: 'eu',
59106
label: 'Are you a european citizen?',
107+
60108
},
61109
{
62110
$formkit: 'primeDropdown',
63-
if: '$get(eu).value', // 👀 Oooo, conditionals!
111+
if: '$eu_citizen', // 👀 Oooo, conditionals!
64112
name: 'cookie_notice',
65113
label: 'Cookie notice frequency',
114+
value: 'hourly',
115+
showClear: false,
116+
filter: false,
66117
optionLabel: 'label',
67118
optionValue: 'value',
68119
options,
69120
help: 'How often should we display a cookie notice?',
121+
class: 'test',
122+
123+
},
124+
{
125+
$formkit: 'primeSlider',
126+
name: 'slider',
127+
label: 'Max messages',
128+
style: 'width: 200px;margin-top: 6px;margin-bottom: 4px',
129+
min: 5,
130+
step: 5,
131+
value: 10,
132+
},
133+
{
134+
$formkit: 'primeChips',
135+
name: 'chips',
136+
label: 'Use Chips',
137+
},
138+
{
139+
$formkit: 'primeKnob',
140+
name: 'knob',
141+
label: 'Use Knob',
142+
value: 50,
70143
},
71144
],
72145
)
73146
74-
const data = ref({ email: '[email protected]' })
75-
76147
async function submitHandler() {
77148
// Lets pretend this is an ajax request:
78149
await new Promise(resolve => setTimeout(resolve, 1000))
79150
}
80151
</script>
81152

82153
<template>
83-
<div class="max-w-xl">
84-
<div class="myFormkit">
85-
<FormKit
86-
id="form"
87-
v-model="data"
88-
type="form"
89-
:submit-attrs="{
90-
inputClass: 'p-button p-component',
91-
}"
92-
@submit="submitHandler"
93-
>
94-
<FormKitSchema :schema="schema" :data="data" />
95-
</FormKit>
154+
<div class="card flex flex-wrap gap-16">
155+
<div class="basis-1/2 md:basis-1/3">
156+
<span class="" />
157+
<div v-if="data" class="myFormkit max-w-30rem">
158+
<FormKit
159+
id="form"
160+
v-model="data"
161+
type="form"
162+
:submit-attrs="{
163+
inputClass: 'p-button p-component',
164+
wrapperClass: '',
165+
outerClass: '',
166+
}"
167+
@submit="submitHandler"
168+
>
169+
<FormKitSchema :schema="schema" :data="data" />
170+
</FormKit>
171+
</div>
172+
</div>
173+
<div class="basis-1/2 md:basis-1/3">
174+
<h2>Formkit Debug</h2>
175+
<h3>Data</h3>
176+
<pre>{{ data }}</pre>
96177
</div>
97-
<h4>Data</h4>
98-
<pre>{{ data }}</pre>
99178
</div>
100179
</template>
180+
181+
<style lang='scss' scoped>
182+
.myFormkit {
183+
184+
}
185+
</style>

src/pages/index.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import AdvertiseBox from '@/components/AdvertiseBox.vue'
3535
Typesafe by default
3636
</AdvertiseBox>
3737

38-
<AdvertiseBox header="PrimeVue 3.49" icon="pi-check-circle" color="green-600">
38+
<AdvertiseBox header="PrimeVue 3.50" icon="pi-check-circle" color="green-600">
3939
Excellent Component Library for VUE
4040
</AdvertiseBox>
4141
<AdvertiseBox header="PrimeVue Theme and Layout" icon="pi-check-circle" color="green-600">
@@ -44,7 +44,7 @@ import AdvertiseBox from '@/components/AdvertiseBox.vue'
4444
<AdvertiseBox header="Uno CSS" icon="pi-check-circle" color="blue-400">
4545
The instant on-demand Atomic CSS engine
4646
</AdvertiseBox>
47-
<AdvertiseBox header="Formkit" icon="pi-check-circle" color="green-600">
47+
<AdvertiseBox header="Formkit 1.6" icon="pi-check-circle" color="green-600">
4848
Formkit PrimeVue Example included
4949
</AdvertiseBox>
5050
<AdvertiseBox header="VueUse" icon="pi-check-circle" color="green-600">

0 commit comments

Comments
 (0)