Skip to content

Instantly share code, notes, and snippets.

@asvae
Created July 8, 2016 15:52
Show Gist options
  • Save asvae/0cac596565396356ad5e42736a20ba35 to your computer and use it in GitHub Desktop.
Save asvae/0cac596565396356ad5e42736a20ba35 to your computer and use it in GitHub Desktop.
vue-multiselect-typeahead
<template>
<div class="ajax-select" :class="{'default': ! isTouched}">
<multiselect
:options="options"
:selected.sync="selected"
:multiple="false"
:placeholder="placeholder"
:on-search-change="fetchData"
key=""
:label="label"
:show-labels="false"
:touched.sync="isTouched"
:on-change="onChange"
@click="onClick"
@focus="onClick"
></multiselect>
</div>
</template>
<script>
import ajaxSelectMixin from './ajax-select-mixin'
export default{
mixins: [ajaxSelectMixin],
methods: {
onClick (){
this.isClicked = true
this.fetchData(null)
},
fetchData (value){
if (! this.isClicked) {
return
}
let originalEntry = {}
originalEntry[this.label] = value
this.options = [originalEntry]
let response = {filters: {}}
response.filters[this.label] = value ? value : ''
this.$api_demo.load(this.source, response)
.then(function (response) {
let options = response.data
options.unshift(originalEntry)
this.options = options
})
},
}
}
</script>
<style lang="scss">
@import 'ajax-select';
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment