question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

featureRequest: Blur ion-input

See original GitHub issue

Feature Request

Ionic version: [x] 4.x

my ionic info:

   Ionic CLI                                                  : 5.4.13
   Ionic Framework                                     : @ionic/angular 4.11.7
   @angular-devkit/build-angular             : 0.803.21
   @angular-devkit/schematics                 : 8.1.3
   @angular/cli                                          : 8.1.3
   @ionic/angular-toolkit                          : 2.0.0

I wanted to blur an ion-input but that’s not working as expected. It just does nothing. No error Messages.

Here’s what I did:

<form (ngSubmit)="safe()">
<ion-input #name [(ngModel)]="name" name="name"></ion-input>
</form>


@ViewChild('name' , { read: ElementRef, static: false }) name: ElementRef;

//static=true doenst work either

safe(){

this.name.nativeElement.blur();

// or this: this.name.nativeElement.setBlur();
}

Is there any other way to blur an ion-input? I didn’t find any functions in the console.log() of the ion-input that could provide such functionality…

I know that ion-input can trigger functions on (ionBlur) but that’s not what I mean…

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Sunny41commented, Jan 23, 2020

thanks @liamdebeasi it worked for me!

1reaction
liamdebeasicommented, Jan 23, 2020

Thanks for the follow up. As @cmer4 mentioned, handling blur/focus is a bit inconsistent across browsers (Safari/iOS typically adds additional restrictions around blur/focus).

I was able to reproduce the behavior you are describing. There is no setBlur or blur method on ion-input; however, we do expose the native input element which can be used to call the blur method. We typically recommend developers just use that method.

@ViewChild('ionInput', { static: true }) ionInput: ElementRef;
...

async blurInput() {
  const nativeInput = await this.ionInput.nativeElement.getInputElement();
  nativeInput.blur();
}

I tried this in your application, and it worked fine. I am going to close this issue. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

featureRequest: Blur ion-input · Issue #20215 · ionic ... - GitHub
I wanted to blur an ion-input but that's not working as expected. It just does nothing. No error Messages. Here's what I did:....
Read more >
How to detect onfocus and blur event of ion-searchbar in ionic2?
To catch focus / blur events on searchbar you should use (ionFocus) and (ionBlur) instead of Angular's (focus) and (blur).
Read more >
Override ion-valid for formgroup in reactive validation - ionic-v3
Folks, I've been trying to create a reactive validation for my register form in angular. Since I want either at least one or...
Read more >
ion-refresher background color - You.com | The search engine you ...
Describe the Feature Request Basically like any other component have an color option to match the ion-refresher with any ion-content background color.
Read more >
angular/angular - Gitter
So basically my servers API will return a json string on a 422 response. Angular used to convert this for me so i...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found