aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/app
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2018-09-27 21:00:29 -0400
committerGitHub <noreply@github.com>2018-09-27 21:00:29 -0400
commita27c78427a3cef06235ea2d05a689b7309d52334 (patch)
treec338116d55f28ea682a662f2de06c3165c98d57e /actionview/app
parent47f2686148bcaa04f24c1ed895d75ff877be12e9 (diff)
parent8e07711d65a10be697020cc775e966bc2df87b7e (diff)
downloadrails-a27c78427a3cef06235ea2d05a689b7309d52334.tar.gz
rails-a27c78427a3cef06235ea2d05a689b7309d52334.tar.bz2
rails-a27c78427a3cef06235ea2d05a689b7309d52334.zip
Merge pull request #31441 from mrhead/rails-ujs-xhr-redirects
Do not enable disabled elements for XHR redirects
Diffstat (limited to 'actionview/app')
-rw-r--r--actionview/app/assets/javascripts/rails-ujs/features/disable.coffee11
1 files changed, 10 insertions, 1 deletions
diff --git a/actionview/app/assets/javascripts/rails-ujs/features/disable.coffee b/actionview/app/assets/javascripts/rails-ujs/features/disable.coffee
index 90aa3bdf0e..a8c692ee62 100644
--- a/actionview/app/assets/javascripts/rails-ujs/features/disable.coffee
+++ b/actionview/app/assets/javascripts/rails-ujs/features/disable.coffee
@@ -8,7 +8,12 @@ Rails.handleDisabledElement = (e) ->
# Unified function to enable an element (link, button and form)
Rails.enableElement = (e) ->
- element = if e instanceof Event then e.target else e
+ if e instanceof Event
+ return if isXhrRedirect(e)
+ element = e.target
+ else
+ element = e
+
if matches(element, Rails.linkDisableSelector)
enableLinkElement(element)
else if matches(element, Rails.buttonDisableSelector) or matches(element, Rails.formEnableSelector)
@@ -80,3 +85,7 @@ enableFormElement = (element) ->
setData(element, 'ujs:enable-with', null) # clean up cache
element.disabled = false
setData(element, 'ujs:disabled', null)
+
+isXhrRedirect = (event) ->
+ xhr = event.detail?[0]
+ xhr?.getResponseHeader("X-Xhr-Redirect")?