|
| 1 | +<template> |
| 2 | + <div class="page container"> |
| 3 | + <div class="mx-auto w-full sm:w-1/2 relative mb-24"> |
| 4 | + <div |
| 5 | + class="absolute inset-0 bg-gradient-to-r from-blue-400 to-green-200 shadow-xl transform -skew-y-3 sm:skew-y-0 sm:-rotate-3 sm:rounded-3xl" |
| 6 | + ></div> |
| 7 | + <div class="relative card p-6 bg-white"> |
| 8 | + <dynamic-form |
| 9 | + :form="form" |
| 10 | + @submitted="handleSubmit" |
| 11 | + @change="valueChanged" |
| 12 | + @error="handleError" |
| 13 | + /> |
| 14 | + <button |
| 15 | + data-cy="submit" |
| 16 | + class="btn bg-green-500 text-white hover:bg-green-700 mt-4" |
| 17 | + submit="true" |
| 18 | + :form="form?.id" |
| 19 | + > |
| 20 | + Try me |
| 21 | + </button> |
| 22 | + </div> |
| 23 | + </div> |
| 24 | + <div class="mx-auto w-full sm:w-1/2"><Console :content="formValues" /></div> |
| 25 | + </div> |
| 26 | +</template> |
| 27 | + |
| 28 | +<script lang="ts"> |
| 29 | +import { CheckboxField, TextField } from '@/'; |
| 30 | +import { computed, defineComponent, reactive } from 'vue'; |
| 31 | +import Console from '../components/Console.vue'; |
| 32 | +
|
| 33 | +const components = { |
| 34 | + Console, |
| 35 | +}; |
| 36 | +/* } from '../../dist/as-dynamic-forms.esm'; */ |
| 37 | +export default defineComponent({ |
| 38 | + name: 'BasicDemo', |
| 39 | + components, |
| 40 | + setup() { |
| 41 | + const formValues = reactive({ |
| 42 | + hideUsingCustomClass: false, |
| 43 | + hideUsingCustomStyles: false, |
| 44 | + }); |
| 45 | +
|
| 46 | + const form = computed(() => ({ |
| 47 | + id: 'basic-demo', |
| 48 | + fields: { |
| 49 | + hideUsingCustomClass: CheckboxField({ |
| 50 | + label: 'Toggle visibility next field with CustomClass', |
| 51 | + }), |
| 52 | + hideMe: TextField({ |
| 53 | + label: 'Using CustomClass', |
| 54 | + customClass: formValues.hideUsingCustomClass |
| 55 | + ? 'invisible' |
| 56 | + : 'visible', |
| 57 | + }), |
| 58 | + hideUsingCustomStyles: CheckboxField({ |
| 59 | + label: 'Toggle visibility next field with CustomStyles', |
| 60 | + }), |
| 61 | + hideMe2: TextField({ |
| 62 | + label: 'Using CustomStyles', |
| 63 | + customStyles: { |
| 64 | + visibility: formValues.hideUsingCustomStyles ? 'hidden' : 'visible', |
| 65 | + }, |
| 66 | + }), |
| 67 | + }, |
| 68 | + })); |
| 69 | +
|
| 70 | + function handleSubmit(values) { |
| 71 | + console.log('Values Submitted', values); |
| 72 | + } |
| 73 | +
|
| 74 | + function valueChanged(values) { |
| 75 | + Object.assign(formValues, values); |
| 76 | + console.log('Values', values); |
| 77 | + } |
| 78 | +
|
| 79 | + function handleError(errors) { |
| 80 | + console.error('Errors', errors); |
| 81 | + } |
| 82 | +
|
| 83 | + return { |
| 84 | + form, |
| 85 | + formValues, |
| 86 | + handleSubmit, |
| 87 | + valueChanged, |
| 88 | + handleError, |
| 89 | + }; |
| 90 | + }, |
| 91 | +}); |
| 92 | +</script> |
| 93 | +<style lang="scss"></style> |
0 commit comments