ng2-ui / auto-complete

Angular Auto Complete component and directive
https://ng2-ui.github.io/dist/#/auto-complete
MIT License
279 stars 122 forks source link

Stop the enter key from hiding the results list? #340

Closed bmdatl closed 6 years ago

bmdatl commented 6 years ago

Essentially, I want to disable the enter key entirely. The user should have to click on one of the results to navigate to it. Currently, hitting the enter key does not select the first item, which is good. However, it hides the results dropdown. I need to prevent this behavior.

I have tried quite a few methods, including checking the keyCode on (keydown) and returning false if it == 13. I also tried playing with most of the attributes in the documentation with no avail. Does anybody know how to do this?

<input ngui-auto-complete
             class="search-primary"
             placeholder="Search for users, groups, events, or courses"
             [source]="search.bind(this)"
             [min-chars]="3"
             [list-formatter]="formatSearch"
             display-property-name="name"
             no-match-found-text="No results found."
             (valueChanged)="inputSelected($event)"
             [(ngModel)]="searchResult">
koktaildotcom commented 6 years ago

I've bypassed the issue by adding the auto-select-first-item="true" argument. That way on <enter>, the first item is selected from the list.

koktaildotcom commented 6 years ago

I've added a PR to prevent that the select list hides on .

bmdatl commented 6 years ago

That doesn't quite solve my issue. If a user is typing in my input and hits "enter" before the search even has a chance to return results, the search is stopped and no results are shown. If there are results, they will go to the first item, true -- but selecting an item in my list navigates the user to another page. I do not want that to happen on enter key.

I need to disable the enter key from having any effect whatsoever. I will keep looking for a solution.

koktaildotcom commented 6 years ago

The workaround is not what you are looking for. The PR i've added does resolve your issue however. It keeps track of the is a 'valid' action.

bmdatl commented 6 years ago

Fantastic! I'll keep an eye out for it. Thank you.