forked from vue-generators/vue-form-generator
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfieldVueMultiSelect.vue
112 lines (111 loc) · 3.21 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<template lang="pug">
multiselect(
:id="fieldOptions.id",
:options="options",
:value="value",
:multiple="fieldOptions.multiple",
:track-by="fieldOptions.trackBy || null",
:label="fieldOptions.label || null",
:searchable="fieldOptions.searchable",
:clear-on-select="fieldOptions.clearOnSelect",
:hide-selected="fieldOptions.hideSelected",
:placeholder="placeholder",
:allow-empty="fieldOptions.allowEmpty",
:reset-after="fieldOptions.resetAfter",
:close-on-select="fieldOptions.closeOnSelect",
:custom-label="customLabel",
:taggable="fieldOptions.taggable",
:tag-placeholder="fieldOptions.tagPlaceholder",
:max="fieldOptions.max || null",
:options-limit="fieldOptions.optionsLimit",
:group-values="fieldOptions.groupValues",
:group-label="fieldOptions.groupLabel",
:block-keys="fieldOptions.blockKeys",
:internal-search="fieldOptions.internalSearch",
:select-label="fieldOptions.selectLabel",
:selected-label="fieldOptions.selectedLabel",
:deselect-label="fieldOptions.deselectLabel",
:show-labels="fieldOptions.showLabels",
:limit="fieldOptions.limit",
:limit-text="fieldOptions.limitText",
:loading="fieldOptions.loading",
:disabled="disabled",
:max-height="fieldOptions.maxHeight",
:show-pointer="fieldOptions.showPointer",
@input="updateSelected",
@select="onSelect",
@remove="onRemove",
@search-change="onSearchChange",
@tag="addTag",
@open="onOpen",
@close="onClose",
:option-height="fieldOptions.optionHeight",
)
span(slot="noResult").
{{ fieldOptions.noResult }}
</template>
<script>
import abstractField from "../abstractField";
export default {
name: "field-vueMultiSelect",
mixins: [abstractField],
computed: {
options() {
let values = this.schema.values;
if (typeof values == "function") {
return values.apply(this, [this.model, this.schema]);
} else {
return values;
}
},
customLabel() {
if (
typeof this.fieldOptions.customLabel !== "undefined" &&
typeof this.fieldOptions.customLabel === "function"
) {
return this.fieldOptions.customLabel;
} else {
// this will let the multiselect library use the default behavior if customLabel is not specified
return undefined;
}
}
},
methods: {
updateSelected(value /* , id*/) {
this.value = value;
},
addTag(newTag, id) {
let onNewTag = this.fieldOptions.onNewTag;
if (typeof onNewTag == "function") {
onNewTag(newTag, id, this.options, this.value);
}
},
onSearchChange(searchQuery, id) {
let onSearch = this.fieldOptions.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 globally
if (!this.$root.$options.components["multiselect"]) {
console.error(
"'vue-multiselect' is missing. Please download from https://github.com/monterail/vue-multiselect and register the component globally!"
);
}
}
};
</script>