diff options
author | Gannon McGibbon <gannon.mcgibbon@gmail.com> | 2019-06-13 17:30:38 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-13 17:30:38 -0400 |
commit | c9e52d028c0347e377177a271486edfb3dac3975 (patch) | |
tree | 2dd1fe11f1f3a19ef267f46d015e0aa26efaf5cf | |
parent | e2d11970f25890e8baa613bfa33e432bd693627b (diff) | |
parent | ab4ed8c78681e0bda514bf6343d54914841a0e72 (diff) | |
download | rails-c9e52d028c0347e377177a271486edfb3dac3975.tar.gz rails-c9e52d028c0347e377177a271486edfb3dac3975.tar.bz2 rails-c9e52d028c0347e377177a271486edfb3dac3975.zip |
Merge pull request #36437 from sudara/fix_programmatic_clicks_with_data_remote
Fix programmatic clicks with data-remote
-rw-r--r-- | actionview/app/assets/javascripts/rails-ujs/features/remote.coffee | 4 | ||||
-rw-r--r-- | actionview/test/ujs/public/test/data-remote.js | 14 |
2 files changed, 16 insertions, 2 deletions
diff --git a/actionview/app/assets/javascripts/rails-ujs/features/remote.coffee b/actionview/app/assets/javascripts/rails-ujs/features/remote.coffee index a5b61220bb..d1aeef56c7 100644 --- a/actionview/app/assets/javascripts/rails-ujs/features/remote.coffee +++ b/actionview/app/assets/javascripts/rails-ujs/features/remote.coffee @@ -88,6 +88,6 @@ Rails.preventInsignificantClick = (e) -> data = link.getAttribute('data-params') metaClick = e.metaKey or e.ctrlKey insignificantMetaClick = metaClick and method is 'GET' and not data - primaryMouseKey = e.button is 0 - e.stopImmediatePropagation() if not primaryMouseKey or insignificantMetaClick + nonPrimaryMouseClick = e.button? and e.button isnt 0 + e.stopImmediatePropagation() if nonPrimaryMouseClick or insignificantMetaClick diff --git a/actionview/test/ujs/public/test/data-remote.js b/actionview/test/ujs/public/test/data-remote.js index 9e41067549..16ea114f3b 100644 --- a/actionview/test/ujs/public/test/data-remote.js +++ b/actionview/test/ujs/public/test/data-remote.js @@ -82,6 +82,20 @@ asyncTest('right/mouse-wheel-clicking on a link does not fire ajaxyness', 0, fun setTimeout(function() { start() }, 13) }) +asyncTest('clicking on a link via a non-mouse Event (such as from js) works', 1, function() { + var link = $('a[data-remote]') + + link + .removeAttr('data-params') + .bindNative('ajax:beforeSend', function() { + ok(true, 'ajax should be triggered') + }) + + Rails.fire(link[0], 'click') + + setTimeout(function() { start() }, 13) +}) + asyncTest('ctrl-clicking on a link still fires ajax for non-GET links and for links with "data-params"', 2, function() { var link = $('a[data-remote]') |