|
1 | 1 | <template lang="jade">
|
2 |
| - multiselect( :selected="selected", :options="options", @update="updateSelected" ) |
| 2 | + multiselect( |
| 3 | + :id="schema.selectOptions.id", |
| 4 | + :options="options", |
| 5 | + :multiple="schema.multiSelect", |
| 6 | + :selected="value", |
| 7 | + :key="schema.selectOptions.key || null", |
| 8 | + :label="schema.selectOptions.label || null", |
| 9 | + :searchable="schema.selectOptions.searchable", |
| 10 | + :clear-on-select="schema.selectOptions.clearOnSelect", |
| 11 | + :hide-selected="schema.selectOptions.hideSelected", |
| 12 | + :placeholder="schema.placeholder", |
| 13 | + :max-height="schema.selectOptions.maxHeight", |
| 14 | + :allow-empty="schema.selectOptions.allowEmpty", |
| 15 | + :reset-after="schema.selectOptions.resetAfter", |
| 16 | + :close-on-select="schema.selectOptions.closeOnSelect", |
| 17 | + :custom-label="schema.selectOptions.customLabel || null", |
| 18 | + :taggable="schema.selectOptions.taggable", |
| 19 | + :tag-placeholder="schema.selectOptions.tagPlaceholder", |
| 20 | + :max="schema.selectOptions.max", |
| 21 | + @update="updateSelected", |
| 22 | + @select="onSelect", |
| 23 | + @remove="onRemove", |
| 24 | + @search-change="onSearchChange", |
| 25 | + @tag="addTag", |
| 26 | + @open="onOpen", |
| 27 | + @close="onClose", |
| 28 | + :show-labels="schema.selectOptions.showLabels" |
| 29 | + // TODO: add other options from multiSelectMixin |
| 30 | + ) |
3 | 31 | </template>
|
4 | 32 | <script>
|
5 | 33 | import { isObject } from "lodash";
|
6 | 34 | import abstractField from "./abstractField";
|
7 | 35 | import Multiselect from 'vue-multiselect';
|
8 | 36 |
|
9 | 37 | export default {
|
10 |
| - mixins: [abstractField], |
11 |
| - components: { Multiselect }, |
12 |
| - computed: { |
13 |
| - options() { |
14 |
| - let values = this.schema.values; |
15 |
| - if (typeof(values) == "function") { |
16 |
| - return values.apply(this, [this.model, this.schema]); |
17 |
| - } else |
18 |
| - return values; |
19 |
| - } |
20 |
| - }, |
| 38 | + mixins: [abstractField], |
| 39 | + components: { |
| 40 | + Multiselect |
| 41 | + }, |
| 42 | + computed: { |
| 43 | + options() { |
| 44 | + let values = this.schema.values; |
| 45 | + if (typeof(values) == "function") { |
| 46 | + return values.apply(this, [this.model, this.schema]); |
| 47 | + } else { |
| 48 | + return values; |
| 49 | + } |
| 50 | + } |
| 51 | + }, |
21 | 52 |
|
22 |
| - methods: { |
23 |
| - updateSelected (newSelected) { |
24 |
| - console.log(newSelected, this.selected) |
25 |
| - this.selected = newSelected |
26 |
| - } |
27 |
| - } |
| 53 | + methods: { |
| 54 | + updateSelected(value, id) { |
| 55 | + this.value = value; |
| 56 | + }, |
| 57 | + onSelect(selectedOption, id) { |
| 58 | + console.log("onSelect", selectedOption, id) |
| 59 | + }, |
| 60 | + onRemove(removedOption, id) { |
| 61 | + console.log("onRemove", removedOption, id) |
| 62 | + }, |
| 63 | + onSearchChange(searchQuery, id) { |
| 64 | + console.log("onSearchChange", searchQuery, id) |
| 65 | + }, |
| 66 | + addTag(newTag, id) { |
| 67 | + console.log("addTag", newTag, id); |
| 68 | + // TODO: implement tag object by sending this function into schema definition |
| 69 | + /* const tag = { |
| 70 | + name: newTag, |
| 71 | + // Just for example needs as we use Array of Objects that should have other properties filled. |
| 72 | + // For primitive values you can simply push the tag into options and selected arrays. |
| 73 | + code: newTag.substring(0, 2) + Math.floor((Math.random() * 10000000)) |
| 74 | + }*/ |
| 75 | + this.options.push(newTag) |
| 76 | + this.value.push(newTag) |
| 77 | + }, |
| 78 | + onOpen(id) { |
| 79 | + console.log("onOpen", id) |
| 80 | + }, |
| 81 | + onClose(value, id) { |
| 82 | + console.log("onClose", value, id) |
| 83 | + }, |
| 84 | + } |
28 | 85 | };
|
29 | 86 | </script>
|
0 commit comments