|
| 1 | +<script setup lang="ts"> |
| 2 | +import { FormKitDataEdit, useFormKitSchema } from 'my-library' |
| 3 | +import { useMessages } from '../../composables/messages' |
| 4 | +
|
| 5 | +const { addElement } = useFormKitSchema() |
| 6 | +const { t } = useI18n() |
| 7 | +const horizontal = ref(false) |
| 8 | +
|
| 9 | +const options = [ |
| 10 | + { label: 'Every page load', value: 'refresh' }, |
| 11 | + { label: 'Every hour', value: 'hourly' }, |
| 12 | + { label: 'Every day', value: 'daily' }, |
| 13 | +] |
| 14 | +
|
| 15 | +const schema = reactive( |
| 16 | + [ |
| 17 | + addElement('h2', ['Register ', '$email']), |
| 18 | + addElement('h3', 'Header Text H3'), |
| 19 | + { |
| 20 | + $formkit: 'primeInputText', |
| 21 | + name: 'email', |
| 22 | + label: 'Email', |
| 23 | + help: 'This will be used for your account.', |
| 24 | + validation: 'required|email', |
| 25 | + prefix: 'test', |
| 26 | + iconPrefix: 'pi pi-trash text-color-red', |
| 27 | + suffix: 'ich suffix net', |
| 28 | + iconSuffix: 'pi pi-trash text-color-blue', |
| 29 | + }, |
| 30 | + { |
| 31 | + $formkit: 'primeTextarea', |
| 32 | + name: 'myText', |
| 33 | + label: 'Text', |
| 34 | + validation: '', |
| 35 | + rows: '3', |
| 36 | + }, |
| 37 | + { |
| 38 | + $formkit: 'primeDatePicker', |
| 39 | + name: 'date', |
| 40 | + label: 'Date', |
| 41 | + }, |
| 42 | + { |
| 43 | + $formkit: 'primeOutputLink', |
| 44 | + name: 'field', |
| 45 | + value: 'https://www.google.de', |
| 46 | + label: 'Output Link', |
| 47 | + iconSuffix: 'pi pi-check', |
| 48 | + suffix: 'This is the suffix', |
| 49 | + prefix: 'This is the prefix', |
| 50 | + iconPrefix: 'pi pi-trash', |
| 51 | + }, |
| 52 | + addElement('h3', 'Password demo'), |
| 53 | + { |
| 54 | + $formkit: 'primePassword', |
| 55 | + name: 'password', |
| 56 | + label: 'Password', |
| 57 | + help: 'Enter your new password.', |
| 58 | + validation: 'required|length:5,16', |
| 59 | + feedback: true, |
| 60 | + outerClass: 'col-6', |
| 61 | + }, |
| 62 | + { |
| 63 | + $formkit: 'primePassword', |
| 64 | + name: 'password_confirm', |
| 65 | + label: 'Confirm password', |
| 66 | + help: 'Enter your new password again.', |
| 67 | + validation: 'required|confirm', |
| 68 | + validationLabel: 'password confirmation', |
| 69 | + outerClass: 'col-6', |
| 70 | + }, |
| 71 | + addElement('h3', 'Conditional Demo'), |
| 72 | + { |
| 73 | + $formkit: 'primeCheckbox', |
| 74 | + name: 'eu_citizen', |
| 75 | + id: 'eu', |
| 76 | + suffix: 'Are you a european citizen?', |
| 77 | + outerClass: 'col-6', |
| 78 | + }, |
| 79 | + { |
| 80 | + $formkit: 'primeSelect', |
| 81 | + if: '$get(eu).value', // 👀 Oooo, conditionals! |
| 82 | + name: 'cookie_notice', |
| 83 | + label: 'Cookie notice frequency', |
| 84 | + optionLabel: 'label', |
| 85 | + optionValue: 'value', |
| 86 | + options, |
| 87 | + help: 'How often should we display a cookie notice?', |
| 88 | + outerClass: 'col-6', |
| 89 | + }, |
| 90 | + ], |
| 91 | +) |
| 92 | +
|
| 93 | +const data = ref({ name: 'Tom', date: new Date(), number: 2222.33, text1: 'Ein Text', text2: 'Lorem Ipsum' }) |
| 94 | +
|
| 95 | +const { showSuccessMessage } = useMessages() |
| 96 | +async function submitHandler() { |
| 97 | + showSuccessMessage('Form Submitted ...', 'Form submitted successfully') |
| 98 | +} |
| 99 | +</script> |
| 100 | + |
| 101 | +<template> |
| 102 | + <PrimeData header="FormKitDataEdit Demo"> |
| 103 | + <div class="flex gap-2 mb-4"> |
| 104 | + Horizontal <ToggleSwitch v-model="horizontal" /> |
| 105 | + </div> |
| 106 | + <FormKitDataEdit |
| 107 | + :data="data" |
| 108 | + :schema="schema" |
| 109 | + :submit-label="t('save')" |
| 110 | + :form-class="horizontal ? 'form-horizontal' : ''" |
| 111 | + :debug-mode="true" |
| 112 | + @data-saved="submitHandler" |
| 113 | + /> |
| 114 | + </PrimeData> |
| 115 | +</template> |
0 commit comments