diff --git a/public/javascripts/application.js b/public/javascripts/application.js index 7076aabcb..c69aa33a8 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -851,7 +851,21 @@ function setupFilePreviewNavigation() { } } - +$(document).on('keydown', 'form input, form textarea', function(e) { + // Submit the form with Ctrl + Enter or Command + Return + var targetForm = $(e.target).closest('form'); + if(e.keyCode == 13 && ((e.ctrlKey && !e.metaKey) || (!e.ctrlKey && e.metaKey) && targetForm.length)) { + $(e.target).closest('form').find('textarea').blur().removeData('changed'); + // Click input[type=submit] if it exists. + // As a workaround for the problem that ajax request fails in `targetForm.submit();` + // Example: new_issue_category modal on the issues/edit + if (targetForm.find('input[type=submit]').length) { + targetForm.find('input[type=submit]').first().click(); + } else { + targetForm.submit(); + } + } +}); function hideOnLoad() { $('.hol').hide();