forked from vue-generators/vue-form-generator
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfieldVueMultiSelect.vue
86 lines (84 loc) · 2.52 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
<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.selectOptions.max",
@update="updateSelected",
@select="onSelect",
@remove="onRemove",
@search-change="onSearchChange",
@tag="addTag",
@open="onOpen",
@close="onClose",
:show-labels="schema.selectOptions.showLabels"
// TODO: add other options from multiSelectMixin
)
</template>
<script>
// import { isObject } from "lodash";
import abstractField from "./abstractField";
import Multiselect from "vue-multiselect";
export default {
mixins: [abstractField],
components: {
Multiselect
},
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;
},
onSelect(selectedOption, id) {
console.log("onSelect", selectedOption, id);
},
onRemove(removedOption, id) {
console.log("onRemove", removedOption, id);
},
onSearchChange(searchQuery, id) {
console.log("onSearchChange", searchQuery, id);
},
addTag(newTag, id) {
console.log("addTag", newTag, id);
// TODO: implement tag object by sending this function into schema definition
/* const tag = {
name: newTag,
// Just for example needs as we use Array of Objects that should have other properties filled.
// For primitive values you can simply push the tag into options and selected arrays.
code: newTag.substring(0, 2) + Math.floor((Math.random() * 10000000))
}*/
this.options.push(newTag);
this.value.push(newTag);
},
onOpen(id) {
console.log("onOpen", id);
},
onClose(value, id) {
console.log("onClose", value, id);
}
}
};
</script>