Skip to content

Instantly share code, notes, and snippets.

@jsguy
Created July 20, 2015 02:01
Show Gist options
  • Save jsguy/21e71fda6b4076901a67 to your computer and use it in GitHub Desktop.
Save jsguy/21e71fda6b4076901a67 to your computer and use it in GitHub Desktop.
Allow click to work even when keyboard is shown on mobile device
/*
Make the submit button "click" even when the keyboard is shown
http://stackoverflow.com/questions/24306818/form-submit-button-event-is-not-captured-when-keyboard-is-up-ios-7
http://stackoverflow.com/questions/12690620/checking-if-touchend-comes-after-a-drag
Note: requires jQuery
*/
$(function(){
// Check if the user is dragging
var isDragging;
$(document).on("touchstart", function () {
isDragging = false;
});
$(document).on("touchmove", function () {
isDragging = true;
});
// The touchend even fires, even when keyboard is open
$(document).on('touchend', 'form :input[type=submit]', function (e) {
if (isDragging) {
return false;
}
// Fire the associated click event
$(this).click();
e.preventDefault();
return false;
});
}(window.jQuery || $));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment