vue2-autocomplete
vue2-autocomplete copied to clipboard
Error occurred when press enter on an empty list
Step for reproducing:
1.enter long string (no autocomplete values);
2.press the enter key;
result: error in console
@
i am also looking for a way to handle this, or an option to load a url at this point
I'm having the same problem here.
For anyone reading this, I had the same problem: I forked the repo and changed line vue-autocomplete.vue:244
into this this.json.length ? this.selectList(this.json[this.focusList]) : e.target.form.submit()
. This was sufficient for my use case, but otherwise you could hook it up to another method.
Another possible way to work around this is to attach a listener to the input and suppress the enter key in appropriate circumstances.
mounted() {
const input = this.$refs.autocomplete.$refs.input
input.addEventListener('keydown', this.suppressEnter, false)
},
methods: {
suppressEnter(e) {
// Enter when there are no results breaks things. This is a bug in the plugin, but this works around it.
if (e.which === 13 && this.results.length === 0) {
e.preventDefault()
return false
}
},