11
11
:key =" control.name"
12
12
:control =" control"
13
13
@changed =" valueChange"
14
- />
14
+ >
15
+ <template v-slot :customField =" props " >
16
+ <div
17
+ v-for =" slot in deNormalizedScopedSlots"
18
+ :key =" slot"
19
+ class =" custom-form-wrapper"
20
+ >
21
+ <slot
22
+ v-if =" props.control.name === slot"
23
+ :name =" slot"
24
+ :control =" normalizedControls[slot]"
25
+ :onChange =" props.onChange"
26
+ :onFocus =" props.onFocus"
27
+ :onBlur =" props.onBlur"
28
+ ></slot >
29
+ </div >
30
+ </template >
31
+ </dynamic-input >
15
32
</form >
16
33
</template >
17
34
@@ -46,7 +63,7 @@ export default defineComponent({
46
63
name: ' asDynamicForm' ,
47
64
props ,
48
65
components ,
49
- setup(props , { emit }) {
66
+ setup(props , { emit , slots }) {
50
67
const controls: Ref <FormControl <any >[]> = ref ([]);
51
68
const formValues = reactive ({});
52
69
const submited = ref (false );
@@ -124,6 +141,16 @@ export default defineComponent({
124
141
emit (' changed' , formValues );
125
142
}
126
143
144
+ const deNormalizedScopedSlots = computed (() => Object .keys (slots ));
145
+
146
+ const normalizedControls = computed (() => {
147
+ let normalizedControls = {};
148
+ controls .value .forEach (element => {
149
+ normalizedControls [element .name ] = element ;
150
+ });
151
+ return normalizedControls ;
152
+ });
153
+
127
154
watch (props , () => {
128
155
mapControls ();
129
156
});
@@ -136,6 +163,9 @@ export default defineComponent({
136
163
handleSubmit ,
137
164
isValid ,
138
165
errors ,
166
+ deNormalizedScopedSlots ,
167
+ normalizedControls ,
168
+ submited ,
139
169
};
140
170
},
141
171
});
0 commit comments