vue2-autocomplete icon indicating copy to clipboard operation
vue2-autocomplete copied to clipboard

Error occurred when press enter on an empty list

Open bonilka opened this issue 6 years ago • 4 comments

Step for reproducing: 1.enter long string (no autocomplete values); 2.press the enter key; result: error in console @browser_2018-03-25_16-54-23

bonilka avatar Mar 25 '18 13:03 bonilka

i am also looking for a way to handle this, or an option to load a url at this point

scripta55 avatar Oct 26 '18 05:10 scripta55

I'm having the same problem here.

MimonCopitman avatar Nov 14 '18 13:11 MimonCopitman

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.

Floriskoch avatar Jun 21 '19 14:06 Floriskoch

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
      }
    },

edwh avatar Aug 06 '19 14:08 edwh