Skip to content

Commit 9df5b5e

Browse files
author
Lionel Bijaoui
committed
added most options from vue-multiselect
1 parent cef52cb commit 9df5b5e

File tree

2 files changed

+93
-25
lines changed

2 files changed

+93
-25
lines changed

dev/schema.js

+18-7
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,23 @@ module.exports = {
8383
type: "vueMultiSelect",
8484
label: "Skills (vue-multiSelect field)",
8585
model: "skills",
86-
multi: true,
8786
required: true,
8887
multiSelect: true,
8988
selectOptions: {
90-
// https://silviomoreto.github.io/bootstrap-select/options/
91-
liveSearch: true,
92-
//maxOptions: 3,
93-
//size: 4,
94-
//actionsBox: true,
95-
selectedTextFormat: "count > 3"
89+
// id:25,
90+
// key:"name",
91+
// label: "name",
92+
searchable:true,
93+
clearOnSelect:true,
94+
hideSelected:true,
95+
// maxHeight:300,
96+
// allowEmpty:true,
97+
// resetAfter:false,
98+
closeOnSelect: true,
99+
// customLabel:function(){return ""},
100+
taggable:true,
101+
tagPlaceholder:'Press enter to create a tag',
102+
max:4
96103
},
97104
values: [
98105
"HTML5",
@@ -103,8 +110,12 @@ module.exports = {
103110
"ReactJS",
104111
"VueJS"
105112
],
113+
onChanged(model, newVal, oldVal, field) {
114+
console.log(`Model's name changed from ${oldVal} to ${newVal}. Model:`, model);
115+
},
106116
min: 2,
107117
max: 4,
118+
placeholder:"Select one Vue",
108119
validator: validators.array
109120
},
110121

src/fields/fieldVueMultiSelect.vue

+75-18
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,86 @@
11
<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+
)
331
</template>
432
<script>
533
import { isObject } from "lodash";
634
import abstractField from "./abstractField";
735
import Multiselect from 'vue-multiselect';
836
937
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+
},
2152
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+
}
2885
};
2986
</script>

0 commit comments

Comments
 (0)