Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ var Autocomplete = require('vue2-autocomplete-js');

</template>

You can optionally use v-model to access and update the text entry field. If You
update the model the component will automatically search for the string entered.

<script>

Expand Down
40 changes: 29 additions & 11 deletions src/js/components/vue-autocomplete.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
>
<a
href="#"
@mousedown.prevent="mousedownList()"
@click.prevent="selectList(data)"
@mousemove="mousemove(i)"
>
Expand Down Expand Up @@ -55,9 +56,25 @@
*
*/

const processInput = function (value) {
this.showList = true;
// Callback Event
if(this.onInput) this.onInput(value)
// If Debounce
if (this.debounce) {
if (this.debounceTask !== undefined) clearTimeout(this.debounceTask)
this.debounceTask = setTimeout(() => {
return this.getData(value)
}, this.debounce)
} else {
return this.getData(value)
}
}

export default {

props: {
value: String,
id: String,
name: String,
className: String,
Expand Down Expand Up @@ -159,6 +176,9 @@
},

watch: {
value(value) {
return processInput.bind(this)(value)
},
options(newVal, oldVal) {
if (this.filterByAnchor) {
const { type, anchor } = this
Expand Down Expand Up @@ -201,17 +221,10 @@
=============================*/
handleInput(e){
const { value } = e.target
this.showList = true;
// Callback Event
if(this.onInput) this.onInput(value)
// If Debounce
if (this.debounce) {
if (this.debounceTask !== undefined) clearTimeout(this.debounceTask)
this.debounceTask = setTimeout(() => {
return this.getData(value)
}, this.debounce)
if (this.value !== undefined) {
this.$emit('input', value)
} else {
return this.getData(value)
return processInput.bind(this)(value)
}
},

Expand Down Expand Up @@ -242,7 +255,6 @@
case ENTER:
e.preventDefault()
this.selectList(this.json[this.focusList])
this.showList = false;
break;
case ESC:
this.showList = false;
Expand Down Expand Up @@ -279,6 +291,12 @@
this.showList = true;
},


// Simply here to prevent default on mouse down so that input field does
// not blur
mousedownList(e){
},

handleBlur(e){
// Callback Event
this.onBlur ? this.onBlur(e) : null
Expand Down