aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage
diff options
context:
space:
mode:
authorJavan Makhmali <javan@javan.us>2018-01-08 17:07:32 -0500
committerJavan Makhmali <javan@javan.us>2018-01-08 17:07:32 -0500
commit21417e02e906f6b64f013aafefdc0cb8ea8b5e74 (patch)
tree0622380caebe66fcf0ed02f81b8861794926c870 /activestorage
parent93e6a0ec55a93fbb20d301763b69029b71d49fe9 (diff)
downloadrails-21417e02e906f6b64f013aafefdc0cb8ea8b5e74.tar.gz
rails-21417e02e906f6b64f013aafefdc0cb8ea8b5e74.tar.bz2
rails-21417e02e906f6b64f013aafefdc0cb8ea8b5e74.zip
Work around Firefox's refusal to dispatch events on disabled elements. Fixes #31393
Brought to you by a 12 year old Firefox bug: https://bugzilla.mozilla.org/show_bug.cgi?id=329509
Diffstat (limited to 'activestorage')
-rw-r--r--activestorage/app/javascript/activestorage/helpers.js11
1 files changed, 10 insertions, 1 deletions
diff --git a/activestorage/app/javascript/activestorage/helpers.js b/activestorage/app/javascript/activestorage/helpers.js
index 52fec8f6f1..7e83c447e7 100644
--- a/activestorage/app/javascript/activestorage/helpers.js
+++ b/activestorage/app/javascript/activestorage/helpers.js
@@ -23,11 +23,20 @@ export function findElement(root, selector) {
}
export function dispatchEvent(element, type, eventInit = {}) {
+ const { disabled } = element
const { bubbles, cancelable, detail } = eventInit
const event = document.createEvent("Event")
+
event.initEvent(type, bubbles || true, cancelable || true)
event.detail = detail || {}
- element.dispatchEvent(event)
+
+ try {
+ element.disabled = false
+ element.dispatchEvent(event)
+ } finally {
+ element.disabled = disabled
+ }
+
return event
}