From 21417e02e906f6b64f013aafefdc0cb8ea8b5e74 Mon Sep 17 00:00:00 2001 From: Javan Makhmali Date: Mon, 8 Jan 2018 17:07:32 -0500 Subject: 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 --- activestorage/app/javascript/activestorage/helpers.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'activestorage') 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 } -- cgit v1.2.3