Skip to content

Commit

Permalink
feat(Validation): FormKit / formkit-primevue
Browse files Browse the repository at this point in the history
  • Loading branch information
sfxcode committed May 24, 2022
1 parent 8ad7137 commit 7b9bb1b
Show file tree
Hide file tree
Showing 7 changed files with 309 additions and 7 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,19 @@ THX to [antfu / Vitesse Nuxt3](https://github.com/antfu/vitesse-nuxt3) for start
- PrimeVue 3.12.x



## Plugins

- [PrimeVue](https://www.primefaces.org/primevue/)

## Nuxt Modules

- [Pinia](https://pinia.esm.dev/) - intuitive, type safe, light and flexible Store for Vue.
- [VueUse](https://github.com/vueuse/vueuse) - collection of useful composition APIs.
- [ColorMode](https://github.com/nuxt-community/color-mode-module) - dark and Light mode with auto detection made easy with Nuxt.
- [FormKit](https://formkit.com/) - Validation, PrimeVue Form elements by [formkit-primevue](https://github.com/sfxcode/formkit-primevue)
- [UnoCSS](https://github.com/antfu/unocss) - the instant on-demand atomic CSS engine.
- [Pinia](https://pinia.esm.dev/) - intuitive, type safe, light and flexible Store for Vue.
- [ColorMode](https://github.com/nuxt-community/color-mode-module) - dark and Light mode with auto detection made easy with Nuxt.


## Variations

Expand Down
1 change: 1 addition & 0 deletions composables/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export function useNavigationMenu() {
items: [
{ label: 'DataTable', icon: 'pi pi-fw pi-table', to: '/prime/table' },
{ label: 'Messages', icon: 'pi pi-fw pi-user-edit', to: '/prime/messages' },
{ label: 'Validation', icon: 'pi pi-fw pi-user-edit', to: '/prime/validation' },
],
},
{
Expand Down
9 changes: 9 additions & 0 deletions formkit.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// formkit.config.ts
import type { DefaultConfigOptions } from '@formkit/vue'
import { primeInputs } from '@sfxcode/formkit-primevue'

const config: DefaultConfigOptions = {
inputs: primeInputs,
}

export default config
3 changes: 3 additions & 0 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default defineNuxtConfig({
'@unocss/nuxt',
'@pinia/nuxt',
'@nuxtjs/color-mode',
'@formkit/nuxt',
],
experimental: {
reactivityTransform: true,
Expand All @@ -38,6 +39,8 @@ export default defineNuxtConfig({
css: [
'primevue/resources/primevue.css',
'primeicons/primeicons.css',
'@sfxcode/formkit-primevue/dist/sass/formkit-prime-inputs.scss',
'@sfxcode/formkit-primevue/dist/sass/formkit-primevue.scss',
],
build: {
transpile: ['primevue'],
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nuxt3-primevue-starter",
"version": "1.0.2",
"version": "1.0.3",
"private": true,
"license": "MIT",
"scripts": {
Expand All @@ -22,13 +22,15 @@
},
"devDependencies": {
"@antfu/eslint-config": "^0.23.1",
"@formkit/nuxt": "1.0.0-beta.8",
"@iconify-json/carbon": "^1.1.3",
"@iconify-json/mdi": "^1.1.10",
"@iconify-json/prime": "^1.1.1",
"@iconify-json/twemoji": "^1.1.3",
"@nuxt/test-utils": "^3.0.0-rc.3",
"@nuxtjs/color-mode": "^3.0.2",
"@pinia/nuxt": "^0.1.8",
"@sfxcode/formkit-primevue": "^0.5.3",
"@unocss/nuxt": "^0.34.0",
"@vitejs/plugin-vue": "^2.3.1",
"@vitest/ui": "^0.12.4",
Expand Down
123 changes: 123 additions & 0 deletions pages/prime/validation.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<script setup lang='ts'>
import { FormKitSchema } from '@formkit/vue'
import { ref } from 'vue'
const options = [
{ label: 'Every page load', value: 'refresh' },
{ label: 'Ever hour', value: 'hourly' },
{ label: 'Every day', value: 'daily' },
]
const schema = reactive(
[
{
$el: 'h1',
children: ['Validation with FormKit'],
},
{
$el: 'h3',
children: ['Inputs from PrimeVue'],
},
{
$formkit: 'primeInputText',
name: 'email',
label: 'Email',
help: 'This will be used for your account.',
validation: 'required|email',
},
{
$formkit: 'primeInputTextArea',
name: 'myText',
label: 'Text',
validation: '',
rows: '5',
},
{
$formkit: 'primeCalendar',
name: 'myCalendar',
label: 'Calendar',
validation: '',
showIcon: true,
},
{
$formkit: 'primeInputText',
name: 'password',
label: 'Password',
help: 'Enter your new password.',
validation: 'required|length:5,16',
validationVisibility: 'live',
},
{
$formkit: 'primePassword',
name: 'password_confirm',
label: 'Confirm password',
toggleMask: true,
feedback: false,
help: 'Enter your new password again to confirm it.',
validation: 'required|confirm',
validationLabel: 'password confirmation',
},
{
$formkit: 'primeCheckBox',
name: 'eu_citizen',
id: 'eu',
label: 'Are you a european citizen?',
},
{
$formkit: 'primeDropdown',
if: '$eu_citizen', // 👀 Oooo, conditionals!
name: 'cookie_notice',
label: 'Cookie notice frequency',
value: 'hourly',
showClear: false,
filter: false,
options,
help: 'How often should we display a cookie notice?',
class: 'test',
},
{
$formkit: 'primeSlider',
name: 'slider',
label: 'Max messages',
min: 5,
step: 5,
value: 10,
},
],
)
const data = ref({})
const submitHandler = async () => {
// Lets pretend this is an ajax request:
await new Promise(resolve => setTimeout(resolve, 1000))
}
</script>

<template>
<div class="myFormkit">
<FormKit
id="form"
v-model="data"
type="form"
:submit-attrs="{
inputClass: 'p-button p-component',
}"
@submit="submitHandler"
>
<FormKitSchema :schema="schema" :data="data" />
</FormKit>
</div>
<h4>Data</h4>
<pre>{{ data }}</pre>
</template>

<style lang='scss' scoped>
.p-inputtext {
width: 500px;
}
</style>
Loading

0 comments on commit 7b9bb1b

Please sign in to comment.