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

First keystroke doesn't register

Open kieraneglin opened this issue 7 years ago • 10 comments

When entering input, the first keystroke never registers and the input remains empty. Only subsequent keystrokes are counted.

Example:

  1. Open this fiddle (taken from another issue): https://jsfiddle.net/196e7sr9/
  2. Try to type in the box

You'll notice that your first keystroke isn't counted. This occurs in both Firefox and Chrome.

kieraneglin avatar Feb 07 '18 18:02 kieraneglin

Of course I stumble upon the fix immediately after submitting! Here's how I fixed it:

My item object was set to an initial value of {}. It seems like the first input was actually changing input from {} to null (both of which cause my getLabel method to return ''), so I changed item to just have an initial value of null.

Simple fix, but it may be worth adding something to the README on the matter.

kieraneglin avatar Feb 07 '18 18:02 kieraneglin

Same issue. If I change item's initial value to null, as you propose, I can't reset input value (when it's just a string, and not an object).

rehfres avatar Feb 08 '18 09:02 rehfres

Please add this to the tutorial, super helpful

sachin-philip avatar Feb 15 '18 05:02 sachin-philip

thanks, this will be done in the next version

paliari avatar Feb 15 '18 15:02 paliari

Thank you @kieraneglin for posting your fix for this :+1:

jewbetcha avatar Mar 13 '18 14:03 jewbetcha

Wow. This was very helpful. Thank you so much. Changing the initial value to null worked for me.

smaharj1 avatar Apr 03 '18 17:04 smaharj1

https://github.com/paliari/v-autocomplete/issues/56#issuecomment-390713387

ghost avatar May 21 '18 16:05 ghost

giving settimeout when clearing input @kieraneglin it will work

https://jsfiddle.net/sprabowo/196e7sr9/22/

sprabowo avatar May 29 '18 06:05 sprabowo

I found that setting the initial value to null only helped the initial case. If the user types some text, selects something, then clears the text and starts typing again, they would again lose the first character.

The solution for me was to add

    ref="autocomplete"
    @change="onChange"

and

        onChange(queryString) {
            this.$nextTick(() => {
                this.$refs.autocomplete.searchText = queryString;
            });
        },

stevage avatar Mar 14 '19 03:03 stevage

Thank you @stevage! Your solution fixed my problem:

iwt-wolfgangfellenz avatar Mar 21 '19 09:03 iwt-wolfgangfellenz