-
Notifications
You must be signed in to change notification settings - Fork 724
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preventing Native Virtual Keyboard from opening #334
Comments
Hi @mreis1! Sadly, I haven't found an ideal solution for hiding the native keyboard. I don't think it's possible to completely disable it with plain javascript. I too would be happy to hear of an alternative that doesn't require loading in an app to turn off the keyboard. |
Hi @Mottie, I'vent tried it yet but some guys at stackoverflow mentioned that triggering the blur event right after the focus will prevent the keyboard from showing. here's my question: |
The problem is that the keyboard returns focus to that input to maintain the caret position (so you can see where you are typing & be able to insert text in the middle, etc). The only way I've found to prevent the native keyboard from opening is to make the input readonly. |
Using the readonly attribute works well in my use case but gives the unexpected behaviour that a hidden clone of the input field with the same name and id is created, which is problematic as I'm integrating the keyboard in a form. Why is this? Also, FWIW, I don't get the backwards input when using the readonly attribute as stated in the docs, I do however get it when using the disabled attribute. |
Hi @membla! That is odd, the preview input (if base.$preview = base.$el.clone(false)
.removeAttr('id') That is the only clone that is produced. Are you using the most up-to-date version? I think the backwards input issue only occurs in some browsers, or it may not be an issue any more. Disabled inputs do not return a caret position and therefore should not have a keyboard applied to it - the plugin only checks for disabled keyboard on initialization. |
Oh wait, I stand corrected... there is a clone of the preview (which is the actual element when |
Thanks for the prompt response @Mottie! I haven't studied your source but why is there a reason for the input clone to be used at all when From my testing I could not reproduce the backwards input when using the |
The reason for the clone is to get an accurate |
Hi guys, just to put you occurrent I managed to block the virtual native keyboard from mobile devices by destroying the keyboard when the keyboard is closed and recreating it each time we need it //here's the click event on the input field
e.preventDefault();
e.stopPropagation();
keyboardOptions = $.extend({},keyboardDefaultSettings, getKeyboardSettings());
var el = $(this),
keyboard = (el.getKeyboard) ? el.getKeyboard() : false;
if (!keyboard) {
el.keyboard (keyboardOptions);
keyboard = el.getkeyboard()
}
keyboard.reveal();
return ; |
Hi @mreis1! I don't see where the keyboard is being destroyed. Also, it would be nice to know what keyboard options are being used. I wonder if the solution is to |
@Mottie I've tried many tricks but here is the explanation. The next move was quiet simple. Because I realize that clicking the input and creating the keyboard was working just fine, so I decided to destroy the keyboard on Guess what... it worked like a charm at least in a Galaxy Tab Android 4.4.x Here's the options used by default: notice the destroy at var keyboardDefaultSettings = {
openOn : null,
layout : 'qwerty',
css: {
// input & preview
input: 'keyboard-input',
// keyboard container
container: 'keyboard-container', // jumbotron
// default state
buttonDefault: 'keyboard-btn keyboard-btn-default',
// hovered button
buttonHover: 'keyboard-btn-hover',
// Action keys (e.g. Accept, Cancel, Tab, etc);
// this replaces "actionClass" option
buttonAction: 'active',
// used when disabling the decimal button {dec}
// when a decimal exists in the input area
buttonDisabled: 'disabled'
},
lockInput: true,
hidden: function(event, keyboard, el){
keyboard.destroy();
}
}; iElement.on(events.click, function(e){
e.preventDefault();
e.stopPropagation();
keyboardOptions = $.extend({},keyboardDefaultSettings, getKeyboardSettings());
var el = $(this),
keyboard = (el.getKeyboard) ? el.getKeyboard() : false;
if (!keyboard) {
el.keyboard (keyboardOptions);
keyboard = el.getkeyboard()
}
keyboard.reveal();
return ;
}); |
This did the job for me, worked on Android 4.2.2 tablet and iPhone (though I don't recommend this for iPhone, as the js-keyboard is very slow => usability) $('input[type="text"]').keyboard({
beforeVisible: function (e, keyboard, el) {
keyboard.el.blur();
}
}); I guess As mentioned by @Mottie, this defeats the caret, so the user can not see where he is inserting the text. |
My solution for stopping the native keyboard to display is to set the Input tag as readonly, then wrap a div around it to which the clicks are captured and trigger the keyboard reveal function. div class="vkeywrapper"> input readonly class="vkey" ... /></div Then UPDATE: I forgot to mention, I have removed from jquery.keyboard.js the part that applies the *-nokeyboard class to readonly elements (this makes the keyboard not being displayed) However, I am facing a problem , that the keyboard is very laggy and deosn't register the keypresses. The keys appear as being pressed visually but they need a long press in order to register. I don't want to reveal the site in public so @Mottie please feel free to contact me about this |
@Handbuch: there is a caret extension which adds a caret that can be styled. Check out the "QWERTY (mod) Text Area" example on the main demo page. Also, check out this demo which uses the caret extension on a password type input. Hi @ioannisth! Are you using the latest version of this plugin? That might solve the laggy problem. Also make sure that the mousewheel plugin is not included. |
I ended up adding |
I'm facing an issue with the virtual keyboard on mobile devices. Basically the native keyboard is showing up and being hidden immediately what causes a flickering in the UI, and bad ux.
I've tried to prevent the click event from propagating and also defined the lockInput property to ensure that the user only uses the virtual keyboard offered by the plugin. I've also tried to prevent the blur effect but the result is the same...
Does anyone have any thoughts on this?
Here's an example of the handler that reveals the keyboard
here are the settings
and here is how i initialize the field. In this case it's suppose to be the email field:
The text was updated successfully, but these errors were encountered: