Input press enter or go

Hi everyone,

How to trigger the action when you press the enter button or the button go on keyboard on the element input.

The method (input) does not recognize when you press enter.

<ion-input (input)="onInput($"> </ion-input>

It just returns the input value


1 Like

You need to use keypress

input type=text (keypress)="eventHandler($event.keyCode)"
eventHandler(keyCode) {…}

to detect enter, check the value 13.


That’s what needed, thank you

It might be a cleaner solution if you wrap it in a form and use

<form (ngSubmit)="save()">
1 Like
      <ion-input (keyup.enter)="onEnter()" type="text" placeholder="نظر " [(ngModel)]="p.reply"></ion-input>

First of all:

  1. Use ‘#’ all the elements in the html
    like this
    <ion-input #Field1 (keyup)="gotoNextField(Field2)" </ion-input>
    <ion-input #Field2 (keyup)="gotoNextField(Field3)" </ion-input>
    <ion-input #Field3 (keyup)="gotoNextField(Field4)" </ion-input>
    <ion-input #Field4 (keyup)="finishFunction()" </ion-input>
  2. use this function
    in the .ts