Wednesday, March 22, 2017

ios 10 autofocus not focusing input

Leave a Comment

When i'm running an application on Desktop or Android device, input focus is working fine. But it's not working in ios 10 Safari. I am using angularjs.

$timeout(function () {   var input = $element.find('.my-input-box')[0];   input.focus(); }, 500); 

3 Answers

Answers 1

Since you are using angularjs, you should definitely try finding your solution in angular.

Did you try using ngFocus.

I guess it would probably look like this:

html:

<input ng-focus="YourVariable"> 

And set YourVariable to True.

Answers 2

I found this https://github.com/angular/material/issues/10080

may be this is helpful to you.

This link said may be it is event/gestured problem.

Answers 3

No need to find the element.You can add a directive instead.

yourApp.directive('autofocus', ['$timeout', function($timeout) {   return {     restrict: 'A',     link : function($scope, $element) {       $timeout(function() {         $element[0].focus();       });     }   } }]); 

and use like :-

<input autofocus type="text"/> 

Here is working example

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment