提交 765403c7 编写于 作者: G Gannon McGibbon

Merge pull request #36437 from sudara/fix_programmatic_clicks_with_data_remote

Fix programmatic clicks with data-remote
上级 e6f32186
* Allow programmatic click events to trigger Rails UJS click handlers.
Programmatic click events (eg. ones generated by `Rails.fire(link, "click")`) don't specify a button. These events were being incorrectly stopped by code meant to ignore scroll wheel and right clicks introduced in #34573.
*Sudara Williams*
## Rails 5.2.3 (March 27, 2019) ##
* Prevent non-primary mouse keys from triggering Rails UJS click handlers.
......
......@@ -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
......@@ -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]')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册