Last active
September 18, 2017 22:13
-
-
Save stevenharman/6054478 to your computer and use it in GitHub Desktop.
⌘-ENTER: submit that form!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).on('keydown', 'form :input:not(:disabled)', function(e) { | |
if(e.keyCode == 13 && (e.metaKey || e.ctrlKey)) { | |
$form = $(this).parents('form') | |
if ($form[0].checkValidity()) { | |
$form.submit(); | |
} | |
} | |
}); |
And if you don't need the input[type=submit]
just hide it.
@jasonkarns Yes, ENTER in non-textarea
will work. This makes for a consistent experience no matter what kind of field you're in.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Isn't it easier to just make sure there is an
input[type=submit]
element in the form? Which there should be, anyway, if it's a submit-able form.[EDIT] After testing this out, I now feel this should be handled by the browser. Currently, plain-ole 'Enter' with any field focused (other than
textarea
) will submit it for you automatically.