1111 :key =" control.name"
1212 :control =" control"
1313 @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 >
1532 </form >
1633</template >
1734
@@ -46,7 +63,7 @@ export default defineComponent({
4663 name: ' asDynamicForm' ,
4764 props ,
4865 components ,
49- setup(props , { emit }) {
66+ setup(props , { emit , slots }) {
5067 const controls: Ref <FormControl <any >[]> = ref ([]);
5168 const formValues = reactive ({});
5269 const submited = ref (false );
@@ -124,6 +141,16 @@ export default defineComponent({
124141 emit (' changed' , formValues );
125142 }
126143
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+
127154 watch (props , () => {
128155 mapControls ();
129156 });
@@ -136,6 +163,9 @@ export default defineComponent({
136163 handleSubmit ,
137164 isValid ,
138165 errors ,
166+ deNormalizedScopedSlots ,
167+ normalizedControls ,
168+ submited ,
139169 };
140170 },
141171});
0 commit comments