Focus on input field and hide keyboard

I’m working on a solution that requires scan barcodes, and with a external Bluetooth barcode scanner.

For the convenience of the user, I make sure that the focus is on the desired input field, and it works fine on Android but not so good on iOS. On the IOS device the keyboard is displayed and will hide other information on the display.Is it possible to have the same behaviour as on Android device, that focus is maintained and that the keyboard is not displayed.

Or are there other solutions?

2 Likes

@me145 how do you focus and still hide keyboard on Android?

1 Like

you could try $event.preventDefault(); and $event.stopImmediatePropagation();

or maybe better --> if input gets focused hide the keyboard via ionic keyboard plugin:
cordova.plugins.Keyboard.close();

Hi, I have a similar need to close soft keyboard on textbox focus. I tried cordova.plugins.keyboard.close() on an ionic project, it didnt work for me. Below is the sequence of steps I have done.

  • ionic start keyboardtest blank
  • ionic platform add android (at the end of this step, ionic keyboard plugin was included by default)
  • Edited index.html to include following line:

<input type=“text” ng-focus=“HideKeyboard($event);” value=“hide”>

  • Edited app.js to include following
.controller("keyboardCtrl", function($scope){
	$scope.HideKeyboard = function(event){
		cordova.plugins.Keyboard.close();
	};
});
  • Changed Android.manifest file to include stateHidden for windowSoftInputMode as below:

android:windowSoftInputMode=“stateHidden|adjustResize”

  • Tested the generated apk file in a phone. Whenever I select the textbox, the soft keyboard displays automatically.

Please let me know on what I am missing here. Thanks.

Setting the input on readonly did the job for me.

2 Likes

I especially logged in to this website to write “Simple & Sweet” here. :heart_eyes: