Skip to content

Instantly share code, notes, and snippets.

@ArthurN
Created January 24, 2018 15:28
Show Gist options
  • Save ArthurN/7e1517385b55dc7c996388597149eca7 to your computer and use it in GitHub Desktop.
Save ArthurN/7e1517385b55dc7c996388597149eca7 to your computer and use it in GitHub Desktop.
Vue wrapper for jquery bootstrap multiselect
<template lang='slm'>
select.form-control multiple="multiple"
option v-for="option in selectOptions" :value='option.value' {{ option.label }}
</template>
<script>
export default {
name: 'bootstrap-multiselect',
props: {
selectOptions: {
type: Array,
required: true,
default: () => { return [] }
},
value: {
type: Array,
required: true,
default: () => { return [] }
},
},
watch: {
value: function(val) {
// TODO: Is there a cleaner multiselect method that does this for us?
$(this.$el).multiselect('deselectAll', false); // second param false = deselect even if dropdown not open
$(this.$el).multiselect('select', val);
}
},
mounted() {
$(this.$el).multiselect({
numberDisplayed: 0,
onChange: () => {
const value = $(this.$el).val() || [];
this.$emit('input', value);
}
}).multiselect('select', this.value);
},
}
</script>
@ahmadalyan
Copy link

how I could use this wrapper

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment