Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

Commit a32579a

Browse files
committed
feat(next): get back to render function on dynamic input
1 parent 227bbeb commit a32579a

File tree

1 file changed

+18
-64
lines changed

1 file changed

+18
-64
lines changed

src/components/dynamic-input/DynamicInput.vue

Lines changed: 18 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,7 @@
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>
381
<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';
405
import TextInput from '@/components/text-input/TextInput.vue';
416
import SelectInput from '@/components/select-input/SelectInput.vue';
427
@@ -59,12 +24,7 @@ export default defineComponent({
5924
components,
6025
props,
6126
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;
6828
6929
const getClasses = computed(() => {
7030
return [
@@ -77,6 +37,13 @@ export default defineComponent({
7737
];
7838
});
7939
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+
8047
const errorMessages = computed(() => {
8148
const errors = values(props?.control?.errors || {});
8249
if (errors.length > 0) {
@@ -127,25 +94,14 @@ export default defineComponent({
12794
}
12895
}
12996
130-
/* const attributes = computed(() => {
97+
const attributes = computed(() => {
13198
return {
13299
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,
139101
};
140-
}); */
141-
return {
142-
valueChange,
143-
errorMessages,
144-
getClasses,
145-
showErrors,
146-
};
102+
});
147103
148-
/* return () => {
104+
return () => {
149105
switch (props?.control?.type) {
150106
case 'text':
151107
case 'email':
@@ -163,10 +119,9 @@ export default defineComponent({
163119
return h(
164120
'div',
165121
{
166-
class: ['dynamic-input', 'form-group', props?.control?.customClass],
122+
class: getClasses.value,
167123
},
168124
[
169-
component,
170125
h(
171126
'label',
172127
{
@@ -175,6 +130,7 @@ export default defineComponent({
175130
},
176131
props?.control?.label,
177132
),
133+
component,
178134
h(
179135
'div',
180136
{
@@ -186,9 +142,7 @@ export default defineComponent({
186142
),
187143
],
188144
);
189-
}; */
145+
};
190146
},
191147
});
192148
</script>
193-
194-
<style></style>

0 commit comments

Comments
 (0)