Ensure non-mouse/programmatic clicks work with data-remote

This commit is contained in:
Sudara 2019-06-06 22:06:14 +02:00
parent cb9c1da695
commit ab4ed8c786
2 changed files with 16 additions and 2 deletions

View File

@ -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

View File

@ -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]')