Open numeric keypad automatically

Asked

Viewed 2,095 times

2

I have a page with a numeric input with autofocus:

<input type="number" placeholder="Informe" ng-model='leitura.leituraatual' required="true" autofocus="true">

The problem is that the keyboard appears in Text mode instead of numerical mode. Only the number pad appears if I click the input manually.

2 answers

1

I found!

I used the plugin Cordova-android-Focus-plugin

<input id="txtLeituraAtual" type="number" >

JS:

$scope.$on('$ionicView.enter', function(){ 
    var txt=$window.document.getElementById("txtLeituraAtual");
    cordova.plugins.Focus.focus(txt);
});

Now the input gets the focus and opens the numeric keyboard correctly!

0

Add the tag below in the file config.xml

<preference name="KeyboardDisplayRequiresUserAction" value="false" />

And then, in the controller, call the method focus() input right after everything is ready.

 $scope.init = function() {
     INPUT_AQUI.focus();
 }

 ...

 $scope.init();
  • I did so: $scope.$on('$ionicView.enter', function(){ $window.document.getElementById("txtLeituraAtual").focus(); });. Now the input even gets the focus but the keyboard does not open.

  • Add cordova.plugins.Keyboard.show(); after the focus() keyboard opens, but in text mode. I wanted it to open in numeric mode.

  • Try to change the type from the input to tel, to test.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.