2
2
/* eslint-disable @typescript-eslint/no-use-before-define */
3
3
4
4
import { defineComponent , PropType , computed , h , inject } from ' vue' ;
5
- import TextInput from ' ../text-input/TextInput.vue' ;
6
- import SelectInput from ' ../select-input/SelectInput.vue' ;
7
- import TextAreaInput from ' ../text-area-input/TextAreaInput.vue' ;
8
- import CheckboxInput from ' ../checkbox-input/CheckboxInput.vue' ;
9
- import RadioInput from ' ../radio-input/RadioInput.vue' ;
10
- import NumberInput from ' ../number-input/NumberInput.vue' ;
11
-
12
- import { FormControl } from ' ../../core/models' ;
5
+ import TextInputComponent from ' ../text-input/TextInput.vue' ;
6
+ import SelectInputComponent from ' ../select-input/SelectInput.vue' ;
7
+ import TextAreaInputComponent from ' ../text-area-input/TextAreaInput.vue' ;
8
+ import CheckboxInputComponent from ' ../checkbox-input/CheckboxInput.vue' ;
9
+ import RadioInputComponent from ' ../radio-input/RadioInput.vue' ;
10
+ import NumberInputComponent from ' ../number-input/NumberInput.vue' ;
11
+
12
+ import {
13
+ FormControl ,
14
+ TextInput ,
15
+ NumberInput ,
16
+ EmailInput ,
17
+ PasswordInput ,
18
+ UrlInput ,
19
+ ColorInput ,
20
+ SelectInput ,
21
+ RadioInput ,
22
+ CheckboxInput ,
23
+ TextAreaInput ,
24
+ } from ' ../../core/models' ;
25
+
13
26
import { isEmpty , entries , values , keys } from ' ../../core/utils/helpers' ;
14
27
import { useInputEvents } from ' ../../composables/input-events' ;
15
28
import { dynamicFormsSymbol } from ' ../../useApi' ;
16
29
17
30
const components = {
18
- TextInput ,
19
- SelectInput ,
20
- TextAreaInput ,
21
- CheckboxInput ,
22
- RadioInput ,
23
- NumberInput ,
31
+ TextInputComponent ,
32
+ SelectInputComponent ,
33
+ TextAreaInputComponent ,
34
+ CheckboxInputComponent ,
35
+ RadioInputComponent ,
36
+ NumberInputComponent ,
24
37
};
25
38
26
39
const props = {
27
40
control: {
28
- type: Object as PropType <FormControl < any > >,
41
+ type: Object as PropType <FormControl >,
29
42
required: true ,
30
43
},
31
44
submited: {
32
45
type: Boolean ,
33
46
required: true ,
34
47
},
35
48
};
49
+
50
+ export type ControlAttribute <T > = {
51
+ control: FormControl <T >;
52
+ onChanged: (value : unknown ) => void ;
53
+ };
54
+
36
55
export default defineComponent ({
37
56
name: ' asDynamicInput' ,
38
57
components ,
@@ -45,7 +64,7 @@ export default defineComponent({
45
64
46
65
const attributes = computed (() => {
47
66
return {
48
- control: props .control ,
67
+ control: props ? .control ,
49
68
onChanged: valueChange ,
50
69
};
51
70
});
@@ -134,26 +153,64 @@ export default defineComponent({
134
153
return () => {
135
154
switch (props ?.control ?.type ) {
136
155
case ' text' :
156
+ component = h (
157
+ TextInputComponent ,
158
+ attributes .value as ControlAttribute <TextInput >,
159
+ );
160
+ break ;
137
161
case ' email' :
162
+ component = h (
163
+ TextInputComponent ,
164
+ attributes .value as ControlAttribute <EmailInput >,
165
+ );
166
+ break ;
138
167
case ' password' :
168
+ component = h (
169
+ TextInputComponent ,
170
+ attributes .value as ControlAttribute <PasswordInput >,
171
+ );
172
+ break ;
139
173
case ' url' :
174
+ component = h (
175
+ TextInputComponent ,
176
+ attributes .value as ControlAttribute <UrlInput >,
177
+ );
178
+ break ;
140
179
case ' color' :
141
- component = h (TextInput , attributes .value );
180
+ component = h (
181
+ TextInputComponent ,
182
+ attributes .value as ControlAttribute <ColorInput >,
183
+ );
142
184
break ;
143
185
case ' number' :
144
- component = h (NumberInput , attributes .value );
186
+ component = h (
187
+ NumberInputComponent ,
188
+ attributes .value as ControlAttribute <NumberInput >,
189
+ );
145
190
break ;
146
191
case ' select' :
147
- component = h (SelectInput , attributes .value );
192
+ component = h (
193
+ SelectInputComponent ,
194
+ attributes .value as ControlAttribute <SelectInput >,
195
+ );
148
196
break ;
149
197
case ' textarea' :
150
- component = h (TextAreaInput , attributes .value );
198
+ component = h (
199
+ TextAreaInputComponent ,
200
+ attributes .value as ControlAttribute <TextAreaInput >,
201
+ );
151
202
break ;
152
203
case ' checkbox' :
153
- component = h (CheckboxInput , attributes .value );
204
+ component = h (
205
+ CheckboxInputComponent ,
206
+ attributes .value as ControlAttribute <CheckboxInput >,
207
+ );
154
208
break ;
155
209
case ' radio' :
156
- component = h (RadioInput , attributes .value );
210
+ component = h (
211
+ RadioInputComponent ,
212
+ attributes .value as ControlAttribute <RadioInput >,
213
+ );
157
214
break ;
158
215
case ' custom-field' :
159
216
component = h (
0 commit comments