Keen-UI icon indicating copy to clipboard operation
Keen-UI copied to clipboard

ui-autocomplete Can I have a keydown-enter event - with code

Open waratah opened this issue 7 years ago • 3 comments

I have a requirement to move fields on enter. I have done this successfully for all but my autocomplete fields. I have a lookup on first, middle and last names and pressing enter should step between them if they are valid. As these are autocomplete I cannot use @keydown-enter like I have for text boxes.

Thanks.

Any work arounds.

waratah avatar Dec 04 '17 06:12 waratah

 selectHighlighted(index, e) {
            if (this.showDropdown && this.$refs.suggestions.length > 0) {
                e.preventDefault();
                this.selectSuggestion(this.$refs.suggestions[index].suggestion);
            }
        },

Would it be a simple matter of emitting the keydown-enter here...

else { this.$emit('keydown-enter'); }

waratah avatar Dec 04 '17 11:12 waratah

selectHighlighted: function selectHighlighted(index, e) {
                            if (this.showDropdown && this.$refs.suggestions && this.$refs.suggestions.length > 0) {
                                e.preventDefault();
                                this.selectSuggestion(this.$refs.suggestions[index].suggestion);
                            } else {
                                this.$emit('keydown-enter');
                            }
                        `},

This worked for me, note the extra protection for the null suggestion.

waratah avatar Dec 04 '17 12:12 waratah

This can probably be done more generally using inheritAttrs, $attrs and $listeners.

JosephusPaye avatar Jul 31 '18 09:07 JosephusPaye