support-ajax-form.patch

Mizuki ISHIKAWA, 2020-10-14 09:18

Download (1.06 KB)

View differences:

public/javascripts/application.js
855 855
  // Submit the form with Ctrl + Enter or Command + Return
856 856
  var targetForm = $(e.target).closest('form');
857 857
  if(e.keyCode == 13 && ((e.ctrlKey && !e.metaKey) || (!e.ctrlKey && e.metaKey) && targetForm.length)) {
858
    $(e.target).closest('form').find('textarea').blur().removeData('changed');
859
    targetForm.submit();
858
    // For ajax, use click() instead of submit() to prevent "Invalid form authenticity token" error
859
    if (targetForm.attr('data-remote') == 'true') {
860
      if (targetForm.find('input[type=submit]').length === 0) { return false; }
861
      targetForm.find('textarea').blur().removeData('changed');
862
      targetForm.find('input[type=submit]').first().click();
863
    } else {
864
      targetForm.find('textarea').blur().removeData('changed');
865
      targetForm.submit();
866
    }
860 867
  }
861 868
});
862 869