@josercl/form-maker 1.0.0-alpha18 → 1.1.0-beta02
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/LICENSE +0 -0
- package/README.md +0 -0
- package/index.js +32 -30
- package/lib/components/FormMaker.vue +133 -147
- package/lib/components/FormMakerInput.vue +36 -41
- package/lib/components/inputs/{TextInput.vue → BasicInput.vue} +10 -17
- package/lib/components/inputs/CheckboxInput.vue +49 -62
- package/lib/components/inputs/FileInput.vue +14 -22
- package/lib/components/inputs/FormInputMixin.js +3 -5
- package/lib/components/inputs/FormMakerInputError.vue +9 -12
- package/lib/components/inputs/FormMakerInputHelp.vue +9 -12
- package/lib/components/inputs/FormMakerInputLabel.vue +13 -16
- 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/utils.js +0 -0
- package/package.json +22 -25
- package/umd/index.umd.js +1 -1095
- package/commonjs/index.common.js +0 -1085
- package/umd/index.umd.min.js +0 -1
package/LICENSE
CHANGED
|
File without changes
|
package/README.md
CHANGED
|
File without changes
|
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/inputs/FormMakerInputError';
|
|
6
|
-
import FormMakerInputHelp from './lib/components/inputs/FormMakerInputHelp';
|
|
7
|
-
import FormMakerInputLabel from './lib/components/inputs/FormMakerInputLabel';
|
|
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/inputs/FormMakerInputError.vue';
|
|
6
|
+
import FormMakerInputHelp from './lib/components/inputs/FormMakerInputHelp.vue';
|
|
7
|
+
import FormMakerInputLabel from './lib/components/inputs/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,135 @@
|
|
|
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)
|
|
97
|
+
.map(key => [
|
|
98
|
+
{
|
|
99
|
+
name: key,
|
|
100
|
+
label: key,
|
|
101
|
+
id: `formMaker_${key}`,
|
|
102
|
+
},
|
|
103
|
+
]);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
const {
|
|
107
|
+
rowClass,
|
|
108
|
+
columnClass,
|
|
109
|
+
labelClass,
|
|
110
|
+
inputGroupClass,
|
|
111
|
+
inputWrapperClass,
|
|
112
|
+
inputErrorClass,
|
|
113
|
+
inputClass,
|
|
114
|
+
errorClass,
|
|
115
|
+
helpTextClass,
|
|
116
|
+
submitButtonClass,
|
|
117
|
+
modelValue,
|
|
118
|
+
} = toRefs(props);
|
|
119
|
+
|
|
120
|
+
provide('labelClass', labelClass.value || inject('form-label'));
|
|
121
|
+
provide('inputGroupClass', inputGroupClass.value || inject('input-group'));
|
|
122
|
+
provide('inputWrapperClass', inputWrapperClass.value || inject('input-wrapper'));
|
|
123
|
+
provide('inputErrorClass', inputErrorClass.value || inject('input-error'));
|
|
124
|
+
provide('inputClass', inputClass.value || inject('input'));
|
|
125
|
+
provide('errorClass', errorClass.value || inject('error'));
|
|
126
|
+
provide('helpTextClass', helpTextClass.value || inject('help-text'));
|
|
127
|
+
|
|
128
|
+
const realRowClass = rowClass.value || inject('form-row');
|
|
129
|
+
const realColumnClass = columnClass.value || inject('form-column');
|
|
130
|
+
const realSubmitButtonClass = submitButtonClass.value || inject('submit-button');
|
|
131
|
+
</script>
|
|
132
|
+
|
|
1
133
|
<template>
|
|
2
134
|
<form
|
|
3
135
|
class="form-maker"
|
|
@@ -25,14 +157,13 @@
|
|
|
25
157
|
:name="`${field.name}`"
|
|
26
158
|
>
|
|
27
159
|
<form-maker-input
|
|
28
|
-
v-model="
|
|
160
|
+
v-model="modelValue[field.name]"
|
|
29
161
|
v-bind="field"
|
|
30
162
|
/>
|
|
31
163
|
</slot>
|
|
32
164
|
</div>
|
|
33
165
|
</div>
|
|
34
166
|
</slot>
|
|
35
|
-
|
|
36
167
|
<slot name="extra" />
|
|
37
168
|
<slot name="divider">
|
|
38
169
|
<hr v-if="hasActions && !hideDivider">
|
|
@@ -54,148 +185,3 @@
|
|
|
54
185
|
</slot>
|
|
55
186
|
</form>
|
|
56
187
|
</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"
|
|
@@ -40,43 +75,3 @@
|
|
|
40
75
|
</slot>
|
|
41
76
|
</div>
|
|
42
77
|
</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,65 +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
|
-
if (selectedOptions.value.indexOf(clickVal) === -1) {
|
|
59
|
-
selectedOptions.value.push(clickVal);
|
|
60
|
-
} else {
|
|
61
|
-
selectedOptions.value = selectedOptions.value.filter(x => x !== clickVal);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (isBinary.value) {
|
|
65
|
-
emit('update:modelValue', selectedOptions.value.length > 0);
|
|
66
|
-
} else {
|
|
67
|
-
emit('update:modelValue', selectedOptions.value);
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
return {
|
|
72
|
-
fieldOptions,
|
|
73
|
-
isBinary,
|
|
74
|
-
selectedOptions,
|
|
75
|
-
handleClick,
|
|
76
|
-
};
|
|
77
|
-
},
|
|
78
|
-
};
|
|
79
|
-
</script>
|
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { FormInputMixin } from './FormInputMixin';
|
|
3
|
+
|
|
4
|
+
defineProps(FormInputMixin.props);
|
|
5
|
+
const emit = defineEmits(FormInputMixin.emits);
|
|
6
|
+
|
|
7
|
+
const handleFileSelect = event => {
|
|
8
|
+
if (event.target.files.length) {
|
|
9
|
+
const file = event.target.files[0];
|
|
10
|
+
emit('update:modelValue', file);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
</script>
|
|
14
|
+
|
|
1
15
|
<template>
|
|
2
16
|
<input
|
|
3
17
|
v-bind="$props"
|
|
@@ -5,25 +19,3 @@
|
|
|
5
19
|
@change="handleFileSelect"
|
|
6
20
|
>
|
|
7
21
|
</template>
|
|
8
|
-
|
|
9
|
-
<script>
|
|
10
|
-
import { FormInputMixin } from './FormInputMixin';
|
|
11
|
-
|
|
12
|
-
export default {
|
|
13
|
-
name: 'FileInput',
|
|
14
|
-
mixins: [ FormInputMixin ],
|
|
15
|
-
emits: [ 'update:modelValue' ],
|
|
16
|
-
setup(props, { emit }) {
|
|
17
|
-
const handleFileSelect = event => {
|
|
18
|
-
if (event.target.files.length) {
|
|
19
|
-
const file = event.target.files[0];
|
|
20
|
-
emit('update:modelValue', file);
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
return {
|
|
25
|
-
handleFileSelect,
|
|
26
|
-
};
|
|
27
|
-
},
|
|
28
|
-
};
|
|
29
|
-
</script>
|
|
@@ -23,9 +23,9 @@ export const injectFormClasses = () => {
|
|
|
23
23
|
export const getFormInputComputeds = props => {
|
|
24
24
|
const { label, error, helpText } = toRefs(props);
|
|
25
25
|
|
|
26
|
-
const hasErrors = computed(() =>
|
|
27
|
-
const hasLabel = computed(() =>
|
|
28
|
-
const hasHelpText = computed(() =>
|
|
26
|
+
const hasErrors = computed(() => Boolean(error.value));
|
|
27
|
+
const hasLabel = computed(() => Boolean(label.value));
|
|
28
|
+
const hasHelpText = computed(() => Boolean(helpText.value));
|
|
29
29
|
|
|
30
30
|
return {
|
|
31
31
|
hasErrors,
|
|
@@ -47,7 +47,5 @@ export const FormInputMixin = {
|
|
|
47
47
|
name: { type: String, default: null },
|
|
48
48
|
placeholder: { type: String, default: null },
|
|
49
49
|
type: { type: String, default: 'text' },
|
|
50
|
-
options: { type: Array, default: () => [] },
|
|
51
|
-
optionGroups: { type: Object, default: () => ({}) },
|
|
52
50
|
},
|
|
53
51
|
};
|