From 472590f6fc2a053d0b685b79c85016385bdc39b2 Mon Sep 17 00:00:00 2001 From: Veiko Aasa Date: Thu, 17 Dec 2020 12:19:25 +0200 Subject: [PATCH] javascript: Fix disabled submit buttons when navigating back to a page When navigating back to a page, enable buttons that were previously **temporarily** disabled. Closes #1996 Tested that on the manage snapshots page, when browsing to delete view and then back, the "Create Snapshot" button is enabled. Signed-off-by: Veiko Aasa Reviewed-by: Sunil Mohan Adapa --- static/themes/default/js/main.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/static/themes/default/js/main.js b/static/themes/default/js/main.js index 487c705f3..5f7167a01 100644 --- a/static/themes/default/js/main.js +++ b/static/themes/default/js/main.js @@ -85,7 +85,9 @@ function onSubmitAddProgress(event) { // Disable all form submit buttons on the page for (const formbutton of getSubmitButtons()) { if (!(formbutton.classList.contains('btn-link') || - formbutton.classList.contains('no-running-status'))) { + formbutton.classList.contains('no-running-status') || + formbutton.hasAttribute('disabled'))) { + formbutton.classList.add('temporarily-disabled'); formbutton.setAttribute('disabled', 'disabled'); } } @@ -105,11 +107,12 @@ document.addEventListener('DOMContentLoaded', function(event) { // back/forward we want them to be able to submit the forms again. So clear all // the button disabling. window.addEventListener('pageshow', function(event) { - const selector = "input[type='submit'].running-status-button"; - const submitButtons = document.querySelectorAll(selector); - for (const button of submitButtons) { + for (const button of getSubmitButtons()) { button.classList.remove('running-status-button'); - button.removeAttribute('disabled'); + if (button.classList.contains('temporarily-disabled')) { + button.classList.remove('temporarily-disabled'); + button.removeAttribute('disabled'); + } } const beforeSelector = ".running-status-button-before";