Akai shur
Akai shur

Reputation: 187

ion-searchbar not triggering my function when using enter button on iOS 13.1

I do have this search bar which a couple of days ago it was working, but with the new version of iOS (13.1) now when I use the enter button it does not search, so I'm guessing they change something and now my function does not trigger anymore, this is what I'm using:

<ion-searchbar [placeholder]="Search" [formControl]="searchInput" (keyup.enter)="searchItems()"></ion-searchbar>

On Android, it's working just fine, any ideas on how to solve this problem?

Thanks in advance!

Upvotes: 1

Views: 2791

Answers (1)

Akai shur
Akai shur

Reputation: 187

I finally solved this problem using keypress instead of keyup and handling the event in the function.

<ion-searchbar [placeholder]="Search" [formControl]="searchInput"(keypress)="searchItems($event)"></ion-searchbar>

EDIT: This way always enters on the function, to solve this I added a condition:

if (event && event.key === "Enter") { // Do stuff}

This way I can handle which key is pressed and do whatever I want.

Upvotes: 4

Related Questions