Newer
Older
<Multiselect data-test="searchUsergroups-selection"
v-model="selection"
style="margin-top: 0.5em;"
class="search-usergroups"
:options="results"
:optionsLimit="10"
:allow-empty="false"
track-by="id"
label="display_name"
:resetAfter="true"
selectLabel=""
selectedLabel=""
deselectLabel=""
:searchable="true"
:placeholder="placeholder"
:showNoResults="true"
:loading="loading"
:clearOnSelect="false"
:preserveSearch="true"
@search-change="search"
@select="select"
>
<template slot="clear">
<div
v-if="selection"
class="multiselect__clear"
data-test="searchUsergroups-removeSelection"
@click.prevent.stop="selection = null"
>
<b-icon-x font-scale="2"/>
</div>
</template>
<span slot="noResult">
</span>
<span slot="noOptions">
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
113
114
115
116
117
118
</span>
</Multiselect>
</div>
</template>
<script>
import Multiselect from 'vue-multiselect';
import { mapState, mapActions } from 'vuex';
export default {
name: 'SearchUsergroups',
components: {
Multiselect
},
props: {
placeholder: {
type: String,
default: 'Ajouter cette organisation à des groupes d\'organisations'
}
},
data() {
return {
selection: null,
loading: false,
text: null,
results: []
};
},
computed: {
...mapState('usergroups', [
'spheres'
])
},
watch: {
text: function(newValue) {
this.loading = true;
this.SEARCH_SPHERES(newValue)
.then(() => {
if (newValue) {
this.results = this.spheres;
} else {
// this.results.splice(0);
this.results = this.spheres;
}
this.loading = false;
});
}
},
created() {
this.GET_SPHERES_LIST()
.then(() => {
this.results = this.spheres;
})
},
methods: {
...mapActions('usergroups', [
'GET_SPHERES_LIST',
'SEARCH_SPHERES'
]),
search(text) {
this.text = text;
},
select(e) {
this.$emit('select', e);
this.selection = null;
}
}
}
</script>