-
Notifications
You must be signed in to change notification settings - Fork 533
/
Copy pathfieldSelectEx.vue
70 lines (57 loc) · 1.67 KB
/
fieldSelectEx.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<template lang="jade">
select.selectpicker(v-model="value", :disabled="disabled", :multiple="schema.multiSelect", :title="schema.placeholder", data-width="100%", :name="schema.inputName")
option(:disabled="schema.required", v-if="schema.multiSelect !== true", :value="null", :selected="value == undefined") <Not selected>
option(v-for="item in items", :value="getItemID(item)") {{ getItemName(item) }}
</template>
<script>
/* global $ */
import {isObject} from "lodash";
import abstractField from "./abstractField";
export default {
mixins: [ abstractField ],
computed: {
items() {
let values = this.schema.values;
if (typeof(values) == "function") {
return values.apply(this, [this.model, this.schema]);
} else
return values;
}
},
methods: {
getItemID(item) {
if (isObject(item) && item.id)
return item.id;
return item;
},
getItemName(item) {
if (isObject(item) && item.name)
return item.name;
return item;
}
},
watch: {
model: function() {
if ($.fn.selectpicker)
$(this.$el).selectpicker("refresh");
}
},
ready() {
if ($.fn.selectpicker)
$(this.$el).selectpicker("destroy").selectpicker(this.schema.selectOptions);
else
console.warn("Bootstrap-select library is missing. Please download from https://silviomoreto.github.io/bootstrap-select/ and load the script and CSS in the HTML head section!");
},
beforeDestroy() {
if ($.fn.selectpicker)
$(this.$el).selectpicker("destroy");
}
};
</script>
<style lang="sass">
.vue-form-generator .field-selectEx .bootstrap-select {
.dropdown-menu li.selected .text{
font-weight: bold;
}
}
</style>