@josercl/form-maker 1.0.0-alpha19 → 1.1.0-beta03
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +32 -30
- package/lib/components/FormMaker.vue +152 -148
- package/lib/components/FormMakerInput.vue +45 -47
- package/lib/components/inputs/{TextInput.vue → BasicInput.vue} +10 -17
- package/lib/components/inputs/CheckboxInput.vue +49 -63
- package/lib/components/inputs/FileInput.vue +14 -22
- package/lib/components/inputs/FormInputMixin.js +3 -5
- package/lib/components/inputs/RadioInput.vue +16 -23
- package/lib/components/inputs/SelectInput.vue +40 -24
- package/lib/components/inputs/TextAreaInput.vue +10 -17
- package/lib/components/texts/FormMakerInputError.vue +5 -0
- package/lib/components/texts/FormMakerInputHelp.vue +5 -0
- package/lib/components/texts/FormMakerInputLabel.vue +15 -0
- package/lib/utils.js +7 -1
- package/package.json +22 -25
- package/umd/index.umd.js +1 -1097
- package/commonjs/index.common.js +0 -1087
- package/lib/components/inputs/FormMakerInputError.vue +0 -15
- package/lib/components/inputs/FormMakerInputHelp.vue +0 -15
- package/lib/components/inputs/FormMakerInputLabel.vue +0 -19
- package/umd/index.umd.min.js +0 -1
package/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import FormMakerComponent from './lib/components/FormMaker';
|
|
2
|
-
import FormMakerInput from './lib/components/FormMakerInput';
|
|
3
|
-
import CheckboxInput from './lib/components/inputs/CheckboxInput';
|
|
4
|
-
import FileInput from './lib/components/inputs/FileInput';
|
|
5
|
-
import FormMakerInputError from './lib/components/
|
|
6
|
-
import FormMakerInputHelp from './lib/components/
|
|
7
|
-
import FormMakerInputLabel from './lib/components/
|
|
8
|
-
import RadioInput from './lib/components/inputs/RadioInput';
|
|
9
|
-
import SelectInput from './lib/components/inputs/SelectInput';
|
|
10
|
-
import TextAreaInput from './lib/components/inputs/TextAreaInput';
|
|
11
|
-
import
|
|
1
|
+
import FormMakerComponent from './lib/components/FormMaker.vue';
|
|
2
|
+
import FormMakerInput from './lib/components/FormMakerInput.vue';
|
|
3
|
+
import CheckboxInput from './lib/components/inputs/CheckboxInput.vue';
|
|
4
|
+
import FileInput from './lib/components/inputs/FileInput.vue';
|
|
5
|
+
import FormMakerInputError from './lib/components/texts/FormMakerInputError.vue';
|
|
6
|
+
import FormMakerInputHelp from './lib/components/texts/FormMakerInputHelp.vue';
|
|
7
|
+
import FormMakerInputLabel from './lib/components/texts/FormMakerInputLabel.vue';
|
|
8
|
+
import RadioInput from './lib/components/inputs/RadioInput.vue';
|
|
9
|
+
import SelectInput from './lib/components/inputs/SelectInput.vue';
|
|
10
|
+
import TextAreaInput from './lib/components/inputs/TextAreaInput.vue';
|
|
11
|
+
import BasicInput from './lib/components/inputs/BasicInput.vue';
|
|
12
12
|
|
|
13
13
|
const defaultOptions = {
|
|
14
14
|
classes: {
|
|
@@ -26,19 +26,19 @@ const defaultOptions = {
|
|
|
26
26
|
'submit-button': 'form-maker-submit',
|
|
27
27
|
},
|
|
28
28
|
components: {
|
|
29
|
-
'form-maker-input-color':
|
|
30
|
-
'form-maker-input-date':
|
|
31
|
-
'form-maker-input-email':
|
|
32
|
-
'form-maker-input-month':
|
|
33
|
-
'form-maker-input-number':
|
|
34
|
-
'form-maker-input-password':
|
|
35
|
-
'form-maker-input-search':
|
|
36
|
-
'form-maker-input-tel':
|
|
37
|
-
'form-maker-input-time':
|
|
38
|
-
'form-maker-input-text':
|
|
39
|
-
'form-maker-input-url':
|
|
40
|
-
'form-maker-input-week':
|
|
41
|
-
'form-maker-input-range':
|
|
29
|
+
'form-maker-input-color': BasicInput,
|
|
30
|
+
'form-maker-input-date': BasicInput,
|
|
31
|
+
'form-maker-input-email': BasicInput,
|
|
32
|
+
'form-maker-input-month': BasicInput,
|
|
33
|
+
'form-maker-input-number': BasicInput,
|
|
34
|
+
'form-maker-input-password': BasicInput,
|
|
35
|
+
'form-maker-input-search': BasicInput,
|
|
36
|
+
'form-maker-input-tel': BasicInput,
|
|
37
|
+
'form-maker-input-time': BasicInput,
|
|
38
|
+
'form-maker-input-text': BasicInput,
|
|
39
|
+
'form-maker-input-url': BasicInput,
|
|
40
|
+
'form-maker-input-week': BasicInput,
|
|
41
|
+
'form-maker-input-range': BasicInput,
|
|
42
42
|
'form-maker-input-file': FileInput,
|
|
43
43
|
'form-maker-input-textarea': TextAreaInput,
|
|
44
44
|
'form-maker-input-select': SelectInput,
|
|
@@ -63,13 +63,15 @@ const FormMaker = {
|
|
|
63
63
|
app.component('FormMaker', FormMakerComponent);
|
|
64
64
|
app.component('FormMakerInput', FormMakerInput);
|
|
65
65
|
|
|
66
|
-
Object.keys(options.classes)
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
Object.keys(options.classes)
|
|
67
|
+
.forEach(key => {
|
|
68
|
+
app.provide(key, options.classes[key]);
|
|
69
|
+
});
|
|
69
70
|
|
|
70
|
-
Object.keys(options.components)
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
Object.keys(options.components)
|
|
72
|
+
.forEach(key => {
|
|
73
|
+
app.component(key, options.components[key]);
|
|
74
|
+
});
|
|
73
75
|
},
|
|
74
76
|
};
|
|
75
77
|
export default FormMaker;
|
|
@@ -1,3 +1,153 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import {
|
|
3
|
+
computed, inject, provide, toRefs
|
|
4
|
+
} from 'vue';
|
|
5
|
+
|
|
6
|
+
const props = defineProps({
|
|
7
|
+
loading: {
|
|
8
|
+
type: Boolean,
|
|
9
|
+
default: false,
|
|
10
|
+
},
|
|
11
|
+
hasActions: {
|
|
12
|
+
type: Boolean,
|
|
13
|
+
default: true,
|
|
14
|
+
},
|
|
15
|
+
modelValue: {
|
|
16
|
+
type: Object,
|
|
17
|
+
default: () => ({}),
|
|
18
|
+
},
|
|
19
|
+
fields: {
|
|
20
|
+
type: Array,
|
|
21
|
+
default: () => [],
|
|
22
|
+
},
|
|
23
|
+
hideDivider: {
|
|
24
|
+
type: Boolean,
|
|
25
|
+
default: false,
|
|
26
|
+
},
|
|
27
|
+
rowClass: {
|
|
28
|
+
type: String,
|
|
29
|
+
default: null,
|
|
30
|
+
},
|
|
31
|
+
columnClass: {
|
|
32
|
+
type: String,
|
|
33
|
+
default: null,
|
|
34
|
+
},
|
|
35
|
+
labelClass: {
|
|
36
|
+
type: String,
|
|
37
|
+
default: null,
|
|
38
|
+
},
|
|
39
|
+
inputGroupClass: {
|
|
40
|
+
type: String,
|
|
41
|
+
default: null,
|
|
42
|
+
},
|
|
43
|
+
inputWrapperClass: {
|
|
44
|
+
type: String,
|
|
45
|
+
default: null,
|
|
46
|
+
},
|
|
47
|
+
inputErrorClass: {
|
|
48
|
+
type: String,
|
|
49
|
+
default: null,
|
|
50
|
+
},
|
|
51
|
+
inputClass: {
|
|
52
|
+
type: String,
|
|
53
|
+
default: null,
|
|
54
|
+
},
|
|
55
|
+
errorClass: {
|
|
56
|
+
type: String,
|
|
57
|
+
default: null,
|
|
58
|
+
},
|
|
59
|
+
helpTextClass: {
|
|
60
|
+
type: String,
|
|
61
|
+
default: null,
|
|
62
|
+
},
|
|
63
|
+
submitButtonClass: {
|
|
64
|
+
type: String,
|
|
65
|
+
default: null,
|
|
66
|
+
},
|
|
67
|
+
submitButtonText: {
|
|
68
|
+
type: String,
|
|
69
|
+
default: 'Submit',
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
const emit = defineEmits([ 'submit', 'update:modelValue' ]);
|
|
74
|
+
|
|
75
|
+
const handleSubmit = () => emit('submit');
|
|
76
|
+
|
|
77
|
+
const formFields = computed(() => {
|
|
78
|
+
if (props.fields.length > 0) {
|
|
79
|
+
return props.fields.map(row => {
|
|
80
|
+
let newRow = row;
|
|
81
|
+
if (!Array.isArray(row)) {
|
|
82
|
+
newRow = [ row ];
|
|
83
|
+
}
|
|
84
|
+
return newRow.map(fieldSpec => {
|
|
85
|
+
if (!fieldSpec.id) {
|
|
86
|
+
return {
|
|
87
|
+
...fieldSpec,
|
|
88
|
+
id: `formMaker_${new Date().getTime()}_${fieldSpec.name}`,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
return fieldSpec;
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return Object.keys(props.modelValue).map(key => [
|
|
97
|
+
{
|
|
98
|
+
name: key,
|
|
99
|
+
label: key,
|
|
100
|
+
id: `formMaker_${key}`,
|
|
101
|
+
},
|
|
102
|
+
]);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
const {
|
|
106
|
+
rowClass,
|
|
107
|
+
columnClass,
|
|
108
|
+
labelClass,
|
|
109
|
+
inputGroupClass,
|
|
110
|
+
inputWrapperClass,
|
|
111
|
+
inputErrorClass,
|
|
112
|
+
inputClass,
|
|
113
|
+
errorClass,
|
|
114
|
+
helpTextClass,
|
|
115
|
+
submitButtonClass,
|
|
116
|
+
modelValue,
|
|
117
|
+
} = toRefs(props);
|
|
118
|
+
|
|
119
|
+
provide('labelClass', labelClass.value || inject('form-label'));
|
|
120
|
+
provide('inputGroupClass', inputGroupClass.value || inject('input-group'));
|
|
121
|
+
provide('inputWrapperClass', inputWrapperClass.value || inject('input-wrapper'));
|
|
122
|
+
provide('inputErrorClass', inputErrorClass.value || inject('input-error'));
|
|
123
|
+
provide('inputClass', inputClass.value || inject('input'));
|
|
124
|
+
provide('errorClass', errorClass.value || inject('error'));
|
|
125
|
+
provide('helpTextClass', helpTextClass.value || inject('help-text'));
|
|
126
|
+
|
|
127
|
+
const realRowClass = rowClass.value || inject('form-row');
|
|
128
|
+
const realColumnClass = columnClass.value || inject('form-column');
|
|
129
|
+
const realSubmitButtonClass = submitButtonClass.value || inject('submit-button');
|
|
130
|
+
|
|
131
|
+
const getObject = fieldName => {
|
|
132
|
+
const fields = fieldName.split('.');
|
|
133
|
+
let result = modelValue.value;
|
|
134
|
+
for (let i = 0; i < fields.length - 1; i += 1) {
|
|
135
|
+
const candidate = result[fields[i]];
|
|
136
|
+
if (!candidate) {
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
result = candidate;
|
|
140
|
+
}
|
|
141
|
+
return result;
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const getProp = fieldName => {
|
|
145
|
+
const fields = fieldName.split('.');
|
|
146
|
+
return fields[fields.length - 1];
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
</script>
|
|
150
|
+
|
|
1
151
|
<template>
|
|
2
152
|
<form
|
|
3
153
|
class="form-maker"
|
|
@@ -16,7 +166,7 @@
|
|
|
16
166
|
:key="`fieldRow_${i}`"
|
|
17
167
|
>
|
|
18
168
|
<div
|
|
19
|
-
v-for="(field,j) in fieldRow"
|
|
169
|
+
v-for="(field, j) in fieldRow"
|
|
20
170
|
:class="[realColumnClass, field.columnClass]"
|
|
21
171
|
:key="`field_${i}_${j}`"
|
|
22
172
|
>
|
|
@@ -25,14 +175,13 @@
|
|
|
25
175
|
:name="`${field.name}`"
|
|
26
176
|
>
|
|
27
177
|
<form-maker-input
|
|
28
|
-
v-model="
|
|
178
|
+
v-model="getObject(field.name)[getProp(field.name)]"
|
|
29
179
|
v-bind="field"
|
|
30
180
|
/>
|
|
31
181
|
</slot>
|
|
32
182
|
</div>
|
|
33
183
|
</div>
|
|
34
184
|
</slot>
|
|
35
|
-
|
|
36
185
|
<slot name="extra" />
|
|
37
186
|
<slot name="divider">
|
|
38
187
|
<hr v-if="hasActions && !hideDivider">
|
|
@@ -54,148 +203,3 @@
|
|
|
54
203
|
</slot>
|
|
55
204
|
</form>
|
|
56
205
|
</template>
|
|
57
|
-
|
|
58
|
-
<script>
|
|
59
|
-
import {
|
|
60
|
-
computed, inject, provide, toRefs,
|
|
61
|
-
} from 'vue';
|
|
62
|
-
// import setupVModel from '../utils';
|
|
63
|
-
|
|
64
|
-
export default {
|
|
65
|
-
name: 'FormMaker',
|
|
66
|
-
emits: [ 'submit', 'update:modelValue' ],
|
|
67
|
-
props: {
|
|
68
|
-
loading: {
|
|
69
|
-
type: Boolean,
|
|
70
|
-
default: false,
|
|
71
|
-
},
|
|
72
|
-
hasActions: {
|
|
73
|
-
type: Boolean,
|
|
74
|
-
default: true,
|
|
75
|
-
},
|
|
76
|
-
modelValue: {
|
|
77
|
-
type: Object,
|
|
78
|
-
default: () => ({}),
|
|
79
|
-
},
|
|
80
|
-
fields: {
|
|
81
|
-
type: Array,
|
|
82
|
-
default: () => [],
|
|
83
|
-
},
|
|
84
|
-
hideDivider: {
|
|
85
|
-
type: Boolean,
|
|
86
|
-
default: false,
|
|
87
|
-
},
|
|
88
|
-
rowClass: {
|
|
89
|
-
type: String,
|
|
90
|
-
default: null,
|
|
91
|
-
},
|
|
92
|
-
columnClass: {
|
|
93
|
-
type: String,
|
|
94
|
-
default: null,
|
|
95
|
-
},
|
|
96
|
-
labelClass: {
|
|
97
|
-
type: String,
|
|
98
|
-
default: null,
|
|
99
|
-
},
|
|
100
|
-
inputGroupClass: {
|
|
101
|
-
type: String,
|
|
102
|
-
default: null,
|
|
103
|
-
},
|
|
104
|
-
inputWrapperClass: {
|
|
105
|
-
type: String,
|
|
106
|
-
default: null,
|
|
107
|
-
},
|
|
108
|
-
inputErrorClass: {
|
|
109
|
-
type: String,
|
|
110
|
-
default: null,
|
|
111
|
-
},
|
|
112
|
-
inputClass: {
|
|
113
|
-
type: String,
|
|
114
|
-
default: null,
|
|
115
|
-
},
|
|
116
|
-
errorClass: {
|
|
117
|
-
type: String,
|
|
118
|
-
default: null,
|
|
119
|
-
},
|
|
120
|
-
helpTextClass: {
|
|
121
|
-
type: String,
|
|
122
|
-
default: null,
|
|
123
|
-
},
|
|
124
|
-
submitButtonClass: {
|
|
125
|
-
type: String,
|
|
126
|
-
default: null,
|
|
127
|
-
},
|
|
128
|
-
submitButtonText: {
|
|
129
|
-
type: String,
|
|
130
|
-
default: 'Submit',
|
|
131
|
-
},
|
|
132
|
-
},
|
|
133
|
-
setup(props, { emit }) {
|
|
134
|
-
const handleSubmit = () => emit('submit');
|
|
135
|
-
|
|
136
|
-
const formFields = computed(() => {
|
|
137
|
-
if (props.fields.length > 0) {
|
|
138
|
-
return props.fields.map(row => {
|
|
139
|
-
let newRow = row;
|
|
140
|
-
if (!Array.isArray(row)) {
|
|
141
|
-
newRow = [ row ];
|
|
142
|
-
}
|
|
143
|
-
return newRow.map(fieldSpec => {
|
|
144
|
-
if (!fieldSpec.id) {
|
|
145
|
-
return {
|
|
146
|
-
...fieldSpec,
|
|
147
|
-
id: `formMaker_${new Date().getTime()}_${fieldSpec.name}`,
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
return fieldSpec;
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
return Object.keys(props.modelValue)
|
|
156
|
-
.map(key => [
|
|
157
|
-
{
|
|
158
|
-
name: key,
|
|
159
|
-
label: key,
|
|
160
|
-
id: `formMaker_${key}`,
|
|
161
|
-
},
|
|
162
|
-
]);
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
const {
|
|
166
|
-
rowClass,
|
|
167
|
-
columnClass,
|
|
168
|
-
labelClass,
|
|
169
|
-
inputGroupClass,
|
|
170
|
-
inputWrapperClass,
|
|
171
|
-
inputErrorClass,
|
|
172
|
-
inputClass,
|
|
173
|
-
errorClass,
|
|
174
|
-
helpTextClass,
|
|
175
|
-
submitButtonClass,
|
|
176
|
-
modelValue,
|
|
177
|
-
} = toRefs(props);
|
|
178
|
-
|
|
179
|
-
provide('labelClass', labelClass.value || inject('form-label'));
|
|
180
|
-
provide('inputGroupClass', inputGroupClass.value || inject('input-group'));
|
|
181
|
-
provide('inputWrapperClass', inputWrapperClass.value || inject('input-wrapper'));
|
|
182
|
-
provide('inputErrorClass', inputErrorClass.value || inject('input-error'));
|
|
183
|
-
provide('inputClass', inputClass.value || inject('input'));
|
|
184
|
-
provide('errorClass', errorClass.value || inject('error'));
|
|
185
|
-
provide('helpTextClass', helpTextClass.value || inject('help-text'));
|
|
186
|
-
|
|
187
|
-
const realRowClass = rowClass.value || inject('form-row');
|
|
188
|
-
const realColumnClass = columnClass.value || inject('form-column');
|
|
189
|
-
const realSubmitButtonClass = submitButtonClass.value || inject('submit-button');
|
|
190
|
-
|
|
191
|
-
return {
|
|
192
|
-
value: modelValue,
|
|
193
|
-
formFields,
|
|
194
|
-
realColumnClass,
|
|
195
|
-
realRowClass,
|
|
196
|
-
realSubmitButtonClass,
|
|
197
|
-
handleSubmit,
|
|
198
|
-
};
|
|
199
|
-
},
|
|
200
|
-
};
|
|
201
|
-
</script>
|
|
@@ -1,5 +1,40 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import setupVModel from '../utils';
|
|
3
|
+
import {
|
|
4
|
+
FormInputMixin,
|
|
5
|
+
injectFormClasses,
|
|
6
|
+
getFormInputComputeds
|
|
7
|
+
} from './inputs/FormInputMixin';
|
|
8
|
+
|
|
9
|
+
const props = defineProps(FormInputMixin.props);
|
|
10
|
+
const emit = defineEmits(FormInputMixin.emits);
|
|
11
|
+
|
|
12
|
+
const value = setupVModel(props, emit);
|
|
13
|
+
|
|
14
|
+
const {
|
|
15
|
+
labelClass,
|
|
16
|
+
inputClass,
|
|
17
|
+
inputWrapperClass,
|
|
18
|
+
inputGroupClass,
|
|
19
|
+
inputErrorClass,
|
|
20
|
+
errorClass,
|
|
21
|
+
helpTextClass,
|
|
22
|
+
} = injectFormClasses();
|
|
23
|
+
|
|
24
|
+
const {
|
|
25
|
+
hasErrors,
|
|
26
|
+
hasLabel,
|
|
27
|
+
hasHelpText,
|
|
28
|
+
} = getFormInputComputeds(props);
|
|
29
|
+
</script>
|
|
30
|
+
<script>
|
|
31
|
+
export default {
|
|
32
|
+
inheritAttrs: false,
|
|
33
|
+
};
|
|
34
|
+
</script>
|
|
35
|
+
|
|
1
36
|
<template>
|
|
2
|
-
<div :class="[ hasErrors && inputErrorClass ]">
|
|
37
|
+
<div :class="[ hasErrors && inputErrorClass, inputWrapperClass ]">
|
|
3
38
|
<slot
|
|
4
39
|
v-if="type !== 'checkbox'"
|
|
5
40
|
name="label"
|
|
@@ -8,8 +43,9 @@
|
|
|
8
43
|
v-if="hasLabel"
|
|
9
44
|
:id="id"
|
|
10
45
|
:class="labelClass"
|
|
11
|
-
|
|
12
|
-
|
|
46
|
+
>
|
|
47
|
+
{{ label }}
|
|
48
|
+
</form-maker-label>
|
|
13
49
|
</slot>
|
|
14
50
|
<slot>
|
|
15
51
|
<div :class="[inputGroupClass, hasErrors && inputErrorClass]">
|
|
@@ -28,55 +64,17 @@
|
|
|
28
64
|
<form-maker-help
|
|
29
65
|
v-if="hasHelpText"
|
|
30
66
|
:class="helpTextClass"
|
|
31
|
-
|
|
32
|
-
|
|
67
|
+
>
|
|
68
|
+
{{ helpText }}
|
|
69
|
+
</form-maker-help>
|
|
33
70
|
</slot>
|
|
34
71
|
<slot name="errors">
|
|
35
72
|
<form-maker-error
|
|
36
73
|
v-if="hasErrors"
|
|
37
74
|
:class="errorClass"
|
|
38
|
-
|
|
39
|
-
|
|
75
|
+
>
|
|
76
|
+
{{ error }}
|
|
77
|
+
</form-maker-error>
|
|
40
78
|
</slot>
|
|
41
79
|
</div>
|
|
42
80
|
</template>
|
|
43
|
-
|
|
44
|
-
<script>
|
|
45
|
-
import setupVModel from '../utils';
|
|
46
|
-
import { FormInputMixin, injectFormClasses, getFormInputComputeds } from './inputs/FormInputMixin';
|
|
47
|
-
|
|
48
|
-
export default {
|
|
49
|
-
name: 'FormMakerInput',
|
|
50
|
-
mixins: [ FormInputMixin ],
|
|
51
|
-
inheritAttrs: false,
|
|
52
|
-
setup(props, { emit }) {
|
|
53
|
-
const value = setupVModel(props, emit);
|
|
54
|
-
|
|
55
|
-
const {
|
|
56
|
-
labelClass,
|
|
57
|
-
inputClass,
|
|
58
|
-
inputWrapperClass,
|
|
59
|
-
inputGroupClass,
|
|
60
|
-
inputErrorClass,
|
|
61
|
-
errorClass,
|
|
62
|
-
helpTextClass,
|
|
63
|
-
} = injectFormClasses();
|
|
64
|
-
|
|
65
|
-
const { hasErrors, hasLabel, hasHelpText } = getFormInputComputeds(props);
|
|
66
|
-
|
|
67
|
-
return {
|
|
68
|
-
value,
|
|
69
|
-
labelClass,
|
|
70
|
-
inputClass,
|
|
71
|
-
inputErrorClass,
|
|
72
|
-
inputGroupClass,
|
|
73
|
-
inputWrapperClass,
|
|
74
|
-
errorClass,
|
|
75
|
-
helpTextClass,
|
|
76
|
-
hasErrors,
|
|
77
|
-
hasLabel,
|
|
78
|
-
hasHelpText,
|
|
79
|
-
};
|
|
80
|
-
},
|
|
81
|
-
};
|
|
82
|
-
</script>
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import setupVModel from '../../utils';
|
|
3
|
+
import { FormInputMixin } from './FormInputMixin';
|
|
4
|
+
|
|
5
|
+
const props = defineProps(FormInputMixin.props);
|
|
6
|
+
const emit = defineEmits(FormInputMixin.emits);
|
|
7
|
+
|
|
8
|
+
const value = setupVModel(props, emit);
|
|
9
|
+
</script>
|
|
10
|
+
|
|
1
11
|
<template>
|
|
2
12
|
<input
|
|
3
13
|
v-model="value"
|
|
@@ -5,20 +15,3 @@
|
|
|
5
15
|
v-bind="$props"
|
|
6
16
|
>
|
|
7
17
|
</template>
|
|
8
|
-
|
|
9
|
-
<script>
|
|
10
|
-
import setupVModel from '../../utils';
|
|
11
|
-
import { FormInputMixin } from './FormInputMixin';
|
|
12
|
-
|
|
13
|
-
export default {
|
|
14
|
-
name: 'TextInput',
|
|
15
|
-
mixins: [ FormInputMixin ],
|
|
16
|
-
setup(props, { emit }) {
|
|
17
|
-
const value = setupVModel(props, emit);
|
|
18
|
-
|
|
19
|
-
return {
|
|
20
|
-
value,
|
|
21
|
-
};
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
</script>
|
|
@@ -1,3 +1,52 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { computed, toRefs } from 'vue';
|
|
3
|
+
import { FormInputMixin } from './FormInputMixin';
|
|
4
|
+
|
|
5
|
+
const props = defineProps({
|
|
6
|
+
...FormInputMixin.props,
|
|
7
|
+
options: { type: Array, default: () => [] },
|
|
8
|
+
});
|
|
9
|
+
const emit = defineEmits(FormInputMixin.emits);
|
|
10
|
+
|
|
11
|
+
const { options, label } = toRefs(props);
|
|
12
|
+
|
|
13
|
+
const isBinary = computed(() => options.value.length === 0);
|
|
14
|
+
|
|
15
|
+
const val = computed(() => props.modelValue);
|
|
16
|
+
|
|
17
|
+
const selectedOptions = computed(() => {
|
|
18
|
+
const arr = Array.isArray(val.value) ? val.value : [ val.value ];
|
|
19
|
+
return arr.filter(x => !!x);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const fieldOptions = computed(() => {
|
|
23
|
+
if (!isBinary.value) {
|
|
24
|
+
return options.value;
|
|
25
|
+
}
|
|
26
|
+
return [
|
|
27
|
+
{
|
|
28
|
+
label: label.value,
|
|
29
|
+
value: true,
|
|
30
|
+
},
|
|
31
|
+
];
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const handleClick = clickVal => {
|
|
35
|
+
let selOptions = [ ...selectedOptions.value ];
|
|
36
|
+
if (selOptions.indexOf(clickVal) === -1) {
|
|
37
|
+
selOptions.push(clickVal);
|
|
38
|
+
} else {
|
|
39
|
+
selOptions = selOptions.filter(x => x !== clickVal);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (isBinary.value) {
|
|
43
|
+
emit('update:modelValue', selOptions.length > 0);
|
|
44
|
+
} else {
|
|
45
|
+
emit('update:modelValue', selOptions);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
</script>
|
|
49
|
+
|
|
1
50
|
<template>
|
|
2
51
|
<div
|
|
3
52
|
v-for="(option,i) in fieldOptions"
|
|
@@ -15,66 +64,3 @@
|
|
|
15
64
|
</label>
|
|
16
65
|
</div>
|
|
17
66
|
</template>
|
|
18
|
-
|
|
19
|
-
<script>
|
|
20
|
-
import { computed, toRefs } from 'vue';
|
|
21
|
-
import { FormInputMixin } from './FormInputMixin';
|
|
22
|
-
|
|
23
|
-
export default {
|
|
24
|
-
name: 'CheckInput',
|
|
25
|
-
mixins: [ FormInputMixin ],
|
|
26
|
-
emits: [ 'update:modelValue' ],
|
|
27
|
-
props: {
|
|
28
|
-
label: {
|
|
29
|
-
type: String,
|
|
30
|
-
default: null,
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
setup(props, { emit }) {
|
|
34
|
-
const { options, label } = toRefs(props);
|
|
35
|
-
|
|
36
|
-
const isBinary = computed(() => options.value.length === 0);
|
|
37
|
-
|
|
38
|
-
const val = computed(() => props.modelValue);
|
|
39
|
-
|
|
40
|
-
const selectedOptions = computed(() => {
|
|
41
|
-
const arr = Array.isArray(val.value) ? val.value : [ val.value ];
|
|
42
|
-
return arr.filter(x => !!x);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
const fieldOptions = computed(() => {
|
|
46
|
-
if (!isBinary.value) {
|
|
47
|
-
return options.value;
|
|
48
|
-
}
|
|
49
|
-
return [
|
|
50
|
-
{
|
|
51
|
-
label: label.value,
|
|
52
|
-
value: true,
|
|
53
|
-
},
|
|
54
|
-
];
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
const handleClick = clickVal => {
|
|
58
|
-
let selOptions = [ ...selectedOptions.value ];
|
|
59
|
-
if (selOptions.indexOf(clickVal) === -1) {
|
|
60
|
-
selOptions.push(clickVal);
|
|
61
|
-
} else {
|
|
62
|
-
selOptions = selOptions.filter(x => x !== clickVal);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (isBinary.value) {
|
|
66
|
-
emit('update:modelValue', selOptions.length > 0);
|
|
67
|
-
} else {
|
|
68
|
-
emit('update:modelValue', selOptions);
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
return {
|
|
73
|
-
fieldOptions,
|
|
74
|
-
isBinary,
|
|
75
|
-
selectedOptions,
|
|
76
|
-
handleClick,
|
|
77
|
-
};
|
|
78
|
-
},
|
|
79
|
-
};
|
|
80
|
-
</script>
|