@qikdev/vue-ui 0.0.3 → 0.0.4
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/package.json +1 -1
- package/src/form/field.vue +7 -0
- package/src/form/inputs/type-select.vue +247 -0
package/package.json
CHANGED
package/src/form/field.vue
CHANGED
|
@@ -35,6 +35,10 @@
|
|
|
35
35
|
<template v-if="widget == 'content-select'">
|
|
36
36
|
<content-select @touched="touch" :field="actualField" v-model="fieldModel" />
|
|
37
37
|
</template>
|
|
38
|
+
|
|
39
|
+
<template v-if="widget == 'type-select'">
|
|
40
|
+
<type-select @touched="touch" :field="actualField" v-model="fieldModel" />
|
|
41
|
+
</template>
|
|
38
42
|
<template v-if="widget == 'richtext'">
|
|
39
43
|
<text-area @touched="touch" :field="actualField" v-model="fieldModel" />
|
|
40
44
|
</template>
|
|
@@ -70,6 +74,7 @@
|
|
|
70
74
|
import PhoneNumberInput from './inputs/phone-number-input.vue';
|
|
71
75
|
import TimezoneSelect from './inputs/timezone.vue';
|
|
72
76
|
import ContentSelect from './inputs/content-select.vue';
|
|
77
|
+
import TypeSelect from './inputs/type-select.vue';
|
|
73
78
|
import CurrencyField from './inputs/currency.vue';
|
|
74
79
|
import TextField from './inputs/textfield.vue';
|
|
75
80
|
import TextArea from './inputs/textarea.vue';
|
|
@@ -137,6 +142,7 @@ export default {
|
|
|
137
142
|
BooleanSwitch: Switch,
|
|
138
143
|
FieldGroup,
|
|
139
144
|
ContentSelect,
|
|
145
|
+
TypeSelect,
|
|
140
146
|
TimezoneSelect,
|
|
141
147
|
PhoneNumberInput,
|
|
142
148
|
Upload,
|
|
@@ -529,6 +535,7 @@ export default {
|
|
|
529
535
|
case 'upload':
|
|
530
536
|
case 'options':
|
|
531
537
|
case 'button':
|
|
538
|
+
case 'type-select':
|
|
532
539
|
break;
|
|
533
540
|
case 'password':
|
|
534
541
|
return 'textfield';
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="native-select" :class="classes">
|
|
3
|
+
<label class="ux-field-title" v-if="showLabel">{{label}} <span class="ux-required-marker" v-if="required">*</span></label>
|
|
4
|
+
<div class="ux-field-description" v-if="showDescription">{{description}}</div>
|
|
5
|
+
<div class="ui-select-button" v-if="singleValue">
|
|
6
|
+
<slot>
|
|
7
|
+
<ux-button tag="div">
|
|
8
|
+
{{summary}}
|
|
9
|
+
</ux-button>
|
|
10
|
+
</slot>
|
|
11
|
+
</div>
|
|
12
|
+
<select @focus="touch" :multiple="multiValue" v-model="model">
|
|
13
|
+
<option value="" v-if="singleValue && !minimum">None</option>
|
|
14
|
+
<option :value="option.value" v-for="option in selectableOptions">{{option.title}}</option>
|
|
15
|
+
</select>
|
|
16
|
+
</div>
|
|
17
|
+
</template>
|
|
18
|
+
<script>
|
|
19
|
+
import InputMixin from './input-mixin';
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
function isUndefined(entry) {
|
|
24
|
+
return entry === undefined || typeof entry === 'undefined' || entry === null || String(entry) === 'null' || String(entry) === 'undefined';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//////////////////////////
|
|
28
|
+
|
|
29
|
+
export default {
|
|
30
|
+
props: {
|
|
31
|
+
title: {
|
|
32
|
+
type: String,
|
|
33
|
+
},
|
|
34
|
+
modelValue: {
|
|
35
|
+
// type: [Object, Array],
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
mixins: [InputMixin],
|
|
39
|
+
async created() {
|
|
40
|
+
this.model = this.model;
|
|
41
|
+
|
|
42
|
+
var glossary = await this.$qik.content.glossary();
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
var typeList = glossary;
|
|
46
|
+
|
|
47
|
+
if (this.field.basicTypes === false) {
|
|
48
|
+
typeList = typeList.filter(function(definition) {
|
|
49
|
+
return !!definition.definesType
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (this.field.definedTypes === false) {
|
|
54
|
+
typeList = typeList.filter(function(definition) {
|
|
55
|
+
return !definition.definesType
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
////////////////////////////
|
|
60
|
+
|
|
61
|
+
typeList = typeList.map(function(definition) {
|
|
62
|
+
return {
|
|
63
|
+
title: definition.title,
|
|
64
|
+
value: definition.key,
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
.sort((a, b) => a.title > b.title ? 1 : -1);
|
|
68
|
+
|
|
69
|
+
////////////////////////////
|
|
70
|
+
|
|
71
|
+
this.types = typeList;
|
|
72
|
+
},
|
|
73
|
+
data() {
|
|
74
|
+
return {
|
|
75
|
+
types: [],
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
methods: {
|
|
79
|
+
cleanOutput(val) {
|
|
80
|
+
var self = this;
|
|
81
|
+
|
|
82
|
+
if (isUndefined(val)) {
|
|
83
|
+
if (self.multiValue) {
|
|
84
|
+
val = [];
|
|
85
|
+
} else {
|
|
86
|
+
val = undefined;
|
|
87
|
+
}
|
|
88
|
+
} else {
|
|
89
|
+
if (self.multiValue) {
|
|
90
|
+
val = (val || []).filter(Boolean).map(function(i) {
|
|
91
|
+
return self.getValue(i);
|
|
92
|
+
})
|
|
93
|
+
} else {
|
|
94
|
+
val = self.getValue(val);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return val;
|
|
99
|
+
},
|
|
100
|
+
cleanInput(val) {
|
|
101
|
+
|
|
102
|
+
var self = this;
|
|
103
|
+
|
|
104
|
+
if (self.multiValue) {
|
|
105
|
+
if (!val) {
|
|
106
|
+
val = [];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (!Array.isArray(val)) {
|
|
110
|
+
val = [val];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/////////////////////////////////
|
|
114
|
+
|
|
115
|
+
if (self.maximum) {
|
|
116
|
+
if (val.length > self.maximum) {
|
|
117
|
+
val.length = self.maximum;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
val = val.filter(Boolean).map(function(v) {
|
|
123
|
+
var valueKey = self.getValue(v);
|
|
124
|
+
return self.returnObject ? self.optionLookup[valueKey] : valueKey;
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
} else {
|
|
128
|
+
var valueKey = self.getValue(val);
|
|
129
|
+
val = self.returnObject ? self.optionLookup[valueKey] : valueKey;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return val;
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
computed: {
|
|
136
|
+
returnObject() {
|
|
137
|
+
return false;
|
|
138
|
+
},
|
|
139
|
+
classes() {
|
|
140
|
+
var array = []
|
|
141
|
+
|
|
142
|
+
if (this.multiValue) {
|
|
143
|
+
array.push('multiple');
|
|
144
|
+
} else {
|
|
145
|
+
array.push('single');
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return array;
|
|
149
|
+
},
|
|
150
|
+
// model: {
|
|
151
|
+
// get() {
|
|
152
|
+
// let val = this.cleanOutput(this.value);
|
|
153
|
+
// return val;
|
|
154
|
+
// },
|
|
155
|
+
// set(val) {
|
|
156
|
+
// val = this.cleanInput(val);
|
|
157
|
+
// // // var val = this.cleanOutput(newValue);
|
|
158
|
+
// // // var existing = this.cleanOutput(this.value);
|
|
159
|
+
|
|
160
|
+
// // if (newValue != existing) {
|
|
161
|
+
// // newValue = this.cleanInput(val);
|
|
162
|
+
// // this.value = newValue;
|
|
163
|
+
// // this.dispatch();
|
|
164
|
+
// // }
|
|
165
|
+
|
|
166
|
+
// this.value = val;
|
|
167
|
+
// this.dispatch();
|
|
168
|
+
|
|
169
|
+
// }
|
|
170
|
+
// },
|
|
171
|
+
optionLookup() {
|
|
172
|
+
var self = this;
|
|
173
|
+
return self.types.reduce(function(set, option) {
|
|
174
|
+
const key = self.getValue(option);
|
|
175
|
+
set[key] = option;
|
|
176
|
+
return set;
|
|
177
|
+
}, {})
|
|
178
|
+
},
|
|
179
|
+
summary() {
|
|
180
|
+
return this.model ? this.getLabel(this.optionLookup[this.model]) : this.title || 'Click to select';
|
|
181
|
+
},
|
|
182
|
+
|
|
183
|
+
selectableOptions() {
|
|
184
|
+
|
|
185
|
+
return this.types;
|
|
186
|
+
// return this.options
|
|
187
|
+
// .sort(function(option) {
|
|
188
|
+
// return option.title;
|
|
189
|
+
// });
|
|
190
|
+
// if(this.type == 'reference') {
|
|
191
|
+
|
|
192
|
+
// } else {
|
|
193
|
+
|
|
194
|
+
// }
|
|
195
|
+
|
|
196
|
+
},
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
</script>
|
|
200
|
+
<style lang="scss" scoped>
|
|
201
|
+
.native-select {
|
|
202
|
+
|
|
203
|
+
cursor: pointer;
|
|
204
|
+
|
|
205
|
+
&.multiple {
|
|
206
|
+
select {
|
|
207
|
+
width: 100%;
|
|
208
|
+
font-size: 1em;
|
|
209
|
+
border: 1px solid rgba(#000, 0.1);
|
|
210
|
+
appearance: none;
|
|
211
|
+
|
|
212
|
+
&:focus {
|
|
213
|
+
border: 1px solid $primary;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
&.single {
|
|
219
|
+
position: relative;
|
|
220
|
+
|
|
221
|
+
.ui-select-button {
|
|
222
|
+
position: relative;
|
|
223
|
+
width: 100%;
|
|
224
|
+
|
|
225
|
+
&>.ux-btn {
|
|
226
|
+
display: block;
|
|
227
|
+
text-align: left;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
select {
|
|
232
|
+
cursor: pointer;
|
|
233
|
+
opacity: 0;
|
|
234
|
+
appearance: none;
|
|
235
|
+
width: 100%;
|
|
236
|
+
height: 100%;
|
|
237
|
+
position: absolute;
|
|
238
|
+
top: 0;
|
|
239
|
+
left: 0;
|
|
240
|
+
bottom: 0;
|
|
241
|
+
right: 0;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
}
|
|
247
|
+
</style>
|