forked from vue-generators/vue-form-generator
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfieldVueMultiSelect.vue
94 lines (92 loc) · 2.84 KB
/
fieldVueMultiSelect.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<template lang="jade">
multiselect(
:id="schema.selectOptions.id",
:options="options",
:multiple="schema.multiSelect",
:selected="value",
:key="schema.selectOptions.key || null",
:label="schema.selectOptions.label || null",
:searchable="schema.selectOptions.searchable",
:clear-on-select="schema.selectOptions.clearOnSelect",
:hide-selected="schema.selectOptions.hideSelected",
:placeholder="schema.placeholder",
:max-height="schema.selectOptions.maxHeight",
:allow-empty="schema.selectOptions.allowEmpty",
:reset-after="schema.selectOptions.resetAfter",
:close-on-select="schema.selectOptions.closeOnSelect",
:custom-label="schema.selectOptions.customLabel || null",
:taggable="schema.selectOptions.taggable",
:tag-placeholder="schema.selectOptions.tagPlaceholder",
:max="schema.max || null",
@update="updateSelected",
@tag="addTag",
@select="onSelect",
@remove="onRemove",
@search-change="onSearchChange",
@open="onOpen",
@close="onClose",
:show-pointer="schema.selectOptions.showPointer",
:select-label="schema.selectOptions.selectLabel",
:selected-label="schema.selectOptions.selectedLabel",
:deselect-label="schema.selectOptions.deselectLabel",
:show-labels="schema.selectOptions.showLabels",
:limit="schema.selectOptions.limit",
:limit-text="schema.selectOptions.limitText",
:loading="schema.selectOptions.loading",
:disabled="disabled",
)
</template>
<script>
import Vue from "vue";
import abstractField from "./abstractField";
export default {
mixins: [abstractField],
computed: {
options() {
let values = this.schema.values;
if (typeof(values) == "function") {
return values.apply(this, [this.model, this.schema]);
} else {
return values;
}
}
},
methods: {
updateSelected(value/*, id*/) {
this.value = value;
},
addTag(newTag, id) {
let onNewTag = this.schema.selectOptions.onNewTag;
if (typeof(onNewTag) == "function") {
onNewTag(newTag, id, this.options, this.value);
}
},
onSearchChange(searchQuery, id) {
let onSearch = this.schema.selectOptions.onSearch;
if (typeof(onSearch) == "function") {
onSearch(searchQuery, id, this.options);
}
},
onSelect(/*selectedOption, id*/) {
// console.log("onSelect", selectedOption, id);
},
onRemove(/*removedOption, id*/) {
// console.log("onRemove", removedOption, id);
},
onOpen(/*id*/) {
// console.log("onOpen", id);
},
onClose(/*value, id*/) {
// console.log("onClose", value, id);
}
},
created() {
// Check if the component is loaded
if (window.VueMultiselect) {
Vue.component("multiselect", window.VueMultiselect.default);
} else {
console.error("'vue-multiselect' is missing. Please download from https://github.com/monterail/vue-multiselect and load the script in the HTML head section!");
}
}
};
</script>