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($event.target.value)"> </ion-input>

It just returns the input value

Thanks.

You need to use keypress

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

to detect enter, check the value 13.

2 Likes

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-item>
      <ion-input (keyup.enter)="onEnter()" type="text" placeholder="نظر " [(ngModel)]="p.reply"></ion-input>
    </ion-item>

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
  gotoNextField(nextElement)
        nextElement.setFocus();
    }