How to unfocus ionic-input when enter is hit

#1

Hi all,

I have an ion-input and want to have a common commenting feature as:

  1. user can input any text
  2. user hits enter key to fire comments out
  3. save text to db table and clean the input text field (to-be-implemented)
  4. the ion-input is unfocused

However, I didnt figure out how to do #3 above.

I have tried event.blur(); or this.textInput.nativeElement.blur(); but it seems neither works.

Please help.

  commentHandler(event) {
    const keyCode = event.keyCode;
    if (keyCode === 13 && this.commentText != "") {
      this.logger.info("enter hit");
      event.blur();
      // this.textInput.nativeElement.blur();
    }
  }
  <ion-item>
    <ion-label floating>Add comment, then hit enter</ion-label>
    <ion-input #commentInput type="text" (keypress)="commentHandler($event)" ngModel="commentText"></ion-input>
  </ion-item>