1
- <template >
2
- <div :class =" getClasses" >
3
- <TextInput
4
- :control =" control"
5
- v-if ="
6
- control.type === 'text' ||
7
- control.type === 'email' ||
8
- control.type === 'password' ||
9
- control.type === 'url' ||
10
- control.type === 'number'
11
- "
12
- @changed =" valueChange"
13
- />
14
- <SelectInput
15
- v-if =" control.type === 'select'"
16
- :control =" control"
17
- @changed =" valueChange"
18
- />
19
- <label
20
- class =" form-label"
21
- :for =" control.name"
22
- v-if =" control.type !== 'checkbox'"
23
- >
24
- {{ control.label }}
25
- </label >
26
- <span class =" form-bar" ></span >
27
- <div class =" form-errors" v-if =" showErrors" >
28
- <p
29
- v-for =" (error, $index) in errorMessages"
30
- :key =" `${$index}`"
31
- class =" form-error"
32
- >
33
- {{ error }}
34
- </p >
35
- </div >
36
- </div >
37
- </template >
38
1
<script lang="ts">
39
- import { defineComponent , PropType , computed , ref , reactive } from ' vue' ;
2
+ /* eslint-disable @typescript-eslint/no-use-before-define */
3
+
4
+ import { defineComponent , PropType , computed , h } from ' vue' ;
40
5
import TextInput from ' @/components/text-input/TextInput.vue' ;
41
6
import SelectInput from ' @/components/select-input/SelectInput.vue' ;
42
7
@@ -59,12 +24,7 @@ export default defineComponent({
59
24
components ,
60
25
props ,
61
26
setup(props , { emit }) {
62
- const showErrors = computed (() => {
63
- return props ?.control ?.errors && keys (props ?.control ?.errors ).length > 0 ;
64
- /* props.control.errors &&
65
- Object.keys(props.control.errors).length > 0 &&
66
- (this.submited || this.autoValidate) */
67
- });
27
+ let component;
68
28
69
29
const getClasses = computed (() => {
70
30
return [
@@ -77,6 +37,13 @@ export default defineComponent({
77
37
];
78
38
});
79
39
40
+ const showErrors = computed (() => {
41
+ return props ?.control ?.errors && keys (props ?.control ?.errors ).length > 0 ;
42
+ /* props.control.errors &&
43
+ Object.keys(props.control.errors).length > 0 &&
44
+ (this.submited || this.autoValidate) */
45
+ });
46
+
80
47
const errorMessages = computed (() => {
81
48
const errors = values (props ?.control ?.errors || {});
82
49
if (errors .length > 0 ) {
@@ -127,25 +94,14 @@ export default defineComponent({
127
94
}
128
95
}
129
96
130
- /* const attributes = computed(() => {
97
+ const attributes = computed (() => {
131
98
return {
132
99
control: props .control ,
133
- onChange: function ($event) {
134
- const value = {};
135
- value[$event.target.name] = $event.target.value;
136
- validate();
137
- emit('changed', value);
138
- },
100
+ onChanged: valueChange ,
139
101
};
140
- }); */
141
- return {
142
- valueChange ,
143
- errorMessages ,
144
- getClasses ,
145
- showErrors ,
146
- };
102
+ });
147
103
148
- /* return () => {
104
+ return () => {
149
105
switch (props ?.control ?.type ) {
150
106
case ' text' :
151
107
case ' email' :
@@ -163,10 +119,9 @@ export default defineComponent({
163
119
return h (
164
120
' div' ,
165
121
{
166
- class: ['dynamic-input', 'form-group', props?.control?.customClass] ,
122
+ class: getClasses . value ,
167
123
},
168
124
[
169
- component,
170
125
h (
171
126
' label' ,
172
127
{
@@ -175,6 +130,7 @@ export default defineComponent({
175
130
},
176
131
props ?.control ?.label ,
177
132
),
133
+ component ,
178
134
h (
179
135
' div' ,
180
136
{
@@ -186,9 +142,7 @@ export default defineComponent({
186
142
),
187
143
],
188
144
);
189
- }; */
145
+ };
190
146
},
191
147
});
192
148
</script >
193
-
194
- <style ></style >
0 commit comments