IONIC keyboard hides on input focus

I am writing an Ionic application that will be used for logistic purposes in the healthcare sector.
The devices to be used for this application have a built-in barcode scanner and are running android 4.1.1.
This scanner enters data into the input field and sends it by pressing the "enter" key. Due to the fact that the scanner is my "keyboard" in certain situations, I want to hide the keyboard on focus or click.

I wrote the following directive using the cordora plugin for ionic keyboard:

directives.directive("showKeyboard", [
function()  {
    var linkFn = function(scope, element, attrs) {
        console.log(scope);
        console.log(element);
        console.log(attrs);
        if(!window.cordova || !window.cordova.plugins.Keyboard) return; // Check for cordova keyboard plugin

        if(element[0].nodeName.toLowerCase() != 'input') return; // check for input

        if(attrs.type.toLowerCase() != 'password' && attrs.type.toLowerCase() != 'text') return; // check for type of input

        element.bind("focus click",
            function(e) {
                e.preventDefault();
                if(scope.$eval(attrs.showKeyboard)){
                    console.log('show')
                    window.cordova.plugins.Keyboard.show();
                }
                else    {
                    console.log('hide');
                    cordova.plugins.Keyboard.close();

                }
            }
        );
    };

    var keyboardDirective = {
        restrict : 'A',
        link: linkFn
    };

    return keyboardDirective;

}
]);  

      

Function

works. Only the keyboard does not close and appears to be "forced" by the device.

any suggestions?

+3


source to share


1 answer


I tried to use your directive to suppress the default keyboard to show an alternative keyboard and found that I had to use $ timout for 100ms before calling hide to close the keyboard (to get around the race condition). However, it creates a flicker artifact, so this is not the best solution. Another idea that I have not tried yet is to suppress the Android side keyboard in Java via a dedicated plugin that will call,



InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);

imm.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);

      

+1


source







All Articles