Forked from alexkingorg/jquery-textarea-form-submit-cmd-enter.js
Last active
September 18, 2015 04:41
-
-
Save silasrm/9d595181ceff8e31ecc9 to your computer and use it in GitHub Desktop.
Submit a form on Command+Enter when in a textarea field.
This file contains hidden or 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
jQuery(function($) { | |
// add a handler for form submit (makes an AJAX call) | |
$(document).on('submit', 'form.my-class', myFormSubmitHandler); | |
// submit form on command + enter if in a textarea | |
$(document).on('keydown', 'body', function(e) { | |
if (!(e.keyCode == 13 && e.metaKey)) return; | |
var $target = $(e.target); | |
if ($target.is('textarea')) { | |
$target.closest('form').submit(); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment