44 <h1 class =" title m-4" >{{ title }}</h1 >
55 <div class =" flex justify-between" >
66 <div class =" card p-6" >
7- <dynamic-form :form =" form" @submited =" handleSubmit" />
7+ <dynamic-form
8+ :form =" form"
9+ @submited =" handleSubmit"
10+ @changed =" valueChanged"
11+ />
812 <button
913 class =" btn bg-teal-500 text-white hover:bg-teal-700 mt-4"
1014 submit =" true"
1418 </button >
1519 </div >
1620 <div class =" card p-6" >
17- <pre >{{ form }}</pre >
21+ <pre >{{ formValues }}</pre >
1822 </div >
1923 </div >
2024 </div >
2125 </div >
2226</template >
2327
2428<script lang="ts">
25- import { defineComponent , reactive , ref , onMounted , Ref } from ' vue' ;
29+ import { defineComponent , reactive , ref } from ' vue' ;
2630import {
2731 TextInput ,
2832 SelectInput ,
2933 DynamicForm ,
3034 EmailInput ,
35+ FormValidation ,
36+ PasswordInput ,
3137} from ' ../../src/index' ;
38+ import { email , pattern } from ' @/core/utils' ;
3239
3340export default defineComponent ({
3441 name: ' app' ,
3542 setup() {
3643 const title = ref (' Vue Dynamic Forms' );
44+ const formValues = reactive ({});
3745 const form = reactive <DynamicForm >({
3846 id: ' example-form' ,
3947 fields: [
4048 new TextInput ({
4149 label: ' Name' ,
50+ value: ' Alvaro' ,
4251 }),
4352 new EmailInput ({
4453 label: ' Email' ,
54+ validations: [new FormValidation (email , ' Email format is incorrect' )],
55+ }),
56+ new PasswordInput ({
57+ label: ' Password' ,
58+ validations: [
59+ new FormValidation (
60+ pattern (
61+ ' ^(?=.*[a-z])(?=.*[A-Z])(?=.*)(?=.*[#$^+=!*()@%&]).{8,10}$' ,
62+ ),
63+ ' Password must contain at least 1 Uppercase, 1 Lowercase, 1 number, 1 special character and min 8 characters max 10' ,
64+ ),
65+ ],
4566 }),
4667 new SelectInput <string >({
4768 label: ' Games' ,
@@ -66,6 +87,9 @@ export default defineComponent({
6687 function handleSubmit(values ) {
6788 console .log (' Values Submitted' , values );
6889 }
90+ function valueChanged(values ) {
91+ Object .assign (formValues , values );
92+ }
6993 /* onMounted(() =>
7094 setTimeout(() => {
7195 form.fields[0].label = 'RockNRoll';
@@ -76,6 +100,8 @@ export default defineComponent({
76100 title ,
77101 form ,
78102 handleSubmit ,
103+ valueChanged ,
104+ formValues ,
79105 };
80106 },
81107});
0 commit comments