This repository was archived by the owner on Jun 27, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +29
-14
lines changed
src/components/dynamic-form Expand file tree Collapse file tree 2 files changed +29
-14
lines changed Original file line number Diff line number Diff line change @@ -39,7 +39,6 @@ export default defineComponent({
39
39
fields: [
40
40
new TextInput ({
41
41
label: ' Name' ,
42
- value: ' Awiwi' ,
43
42
}),
44
43
new EmailInput ({
45
44
label: ' Email' ,
@@ -67,12 +66,12 @@ export default defineComponent({
67
66
function handleSubmit(values ) {
68
67
console .log (' Values Submitted' , values );
69
68
}
70
- onMounted (() =>
69
+ /* onMounted(() =>
71
70
setTimeout(() => {
72
71
form.fields[0].label = 'RockNRoll';
73
72
form.fields[0].value = 'James Bond';
74
73
}, 2000),
75
- );
74
+ ); */
76
75
return {
77
76
title ,
78
77
form ,
Original file line number Diff line number Diff line change @@ -47,11 +47,31 @@ export default defineComponent({
47
47
const controls: Ref <FormControl <any >[] | undefined > = ref ([]);
48
48
const formValues = reactive ({});
49
49
const submited = ref (false );
50
- watchEffect (() => {
50
+
51
+ function valueChanged(changedValue : any ) {
52
+ Object .assign (formValues , changedValue );
53
+ }
54
+
55
+ function mapControls(empty ? ) {
51
56
controls .value =
52
- props .form ?.fields ?.map (
53
- (field : InputBase <any >) => new FormControl ({ ... field }),
57
+ props .form ?.fields ?.map ((field : InputBase <any >) =>
58
+ empty
59
+ ? new FormControl ({ ... field , value: null })
60
+ : new FormControl ({ ... field }),
54
61
) || [];
62
+ }
63
+
64
+ function resetForm() {
65
+ mapControls (true );
66
+ }
67
+
68
+ function handleSubmit() {
69
+ submited .value = true ;
70
+ emit (' submited' , formValues );
71
+ resetForm ();
72
+ }
73
+
74
+ function initValues() {
55
75
Object .assign (
56
76
formValues ,
57
77
controls .value
@@ -66,16 +86,12 @@ export default defineComponent({
66
86
}, {})
67
87
: {},
68
88
);
69
- });
70
-
71
- function valueChanged(changedValue : any ) {
72
- Object .assign (formValues , changedValue );
73
89
}
74
90
75
- function handleSubmit() {
76
- submited . value = true ;
77
- emit ( ' submited ' , formValues );
78
- }
91
+ watchEffect (() => {
92
+ mapControls () ;
93
+ initValues ( );
94
+ });
79
95
80
96
return {
81
97
controls ,
You can’t perform that action at this time.
0 commit comments