4
4
<h1 class =" title m-4" >{{ title }}</h1 >
5
5
<div class =" flex justify-between" >
6
6
<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
+ />
8
12
<button
9
13
class =" btn bg-teal-500 text-white hover:bg-teal-700 mt-4"
10
14
submit =" true"
14
18
</button >
15
19
</div >
16
20
<div class =" card p-6" >
17
- <pre >{{ form }}</pre >
21
+ <pre >{{ formValues }}</pre >
18
22
</div >
19
23
</div >
20
24
</div >
21
25
</div >
22
26
</template >
23
27
24
28
<script lang="ts">
25
- import { defineComponent , reactive , ref , onMounted , Ref } from ' vue' ;
29
+ import { defineComponent , reactive , ref } from ' vue' ;
26
30
import {
27
31
TextInput ,
28
32
SelectInput ,
29
33
DynamicForm ,
30
34
EmailInput ,
35
+ FormValidation ,
36
+ PasswordInput ,
31
37
} from ' ../../src/index' ;
38
+ import { email , pattern } from ' @/core/utils' ;
32
39
33
40
export default defineComponent ({
34
41
name: ' app' ,
35
42
setup() {
36
43
const title = ref (' Vue Dynamic Forms' );
44
+ const formValues = reactive ({});
37
45
const form = reactive <DynamicForm >({
38
46
id: ' example-form' ,
39
47
fields: [
40
48
new TextInput ({
41
49
label: ' Name' ,
50
+ value: ' Alvaro' ,
42
51
}),
43
52
new EmailInput ({
44
53
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
+ ],
45
66
}),
46
67
new SelectInput <string >({
47
68
label: ' Games' ,
@@ -66,6 +87,9 @@ export default defineComponent({
66
87
function handleSubmit(values ) {
67
88
console .log (' Values Submitted' , values );
68
89
}
90
+ function valueChanged(values ) {
91
+ Object .assign (formValues , values );
92
+ }
69
93
/* onMounted(() =>
70
94
setTimeout(() => {
71
95
form.fields[0].label = 'RockNRoll';
@@ -76,6 +100,8 @@ export default defineComponent({
76
100
title ,
77
101
form ,
78
102
handleSubmit ,
103
+ valueChanged ,
104
+ formValues ,
79
105
};
80
106
},
81
107
});
0 commit comments