From 614ef6341fdd97b378e5c61c55b13ac1adcf694e Mon Sep 17 00:00:00 2001 From: Ishan Masdekar Date: Sat, 13 Jul 2024 23:34:21 +0530 Subject: [PATCH] fix: correctly handles the enabling of submit button on reset - disables the submit button on the click of reset button except for the cases when there is a gentle alert notification. closes openedx/frontend-app-learning#1406 Signed-off by: Ishan Masdekar --- xmodule/js/src/capa/display.js | 42 +++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/xmodule/js/src/capa/display.js b/xmodule/js/src/capa/display.js index f4254b43f8ff..f88c28fe83ac 100644 --- a/xmodule/js/src/capa/display.js +++ b/xmodule/js/src/capa/display.js @@ -1223,14 +1223,50 @@ */ Problem.prototype.disableAllButtonsWhileRunning = function(operationCallback, isFromCheckOperation) { var that = this; - var allButtons = [this.resetButton, this.saveButton, this.showButton, this.hintButton, this.submitButton]; - var initiallyEnabledButtons = allButtons.filter(function(button) { + + // Array of all buttons except the submit button + var buttonsExceptSubmit = [this.resetButton, this.saveButton, this.showButton, this.hintButton]; + // Array containing only the submit button + var submitButtonArr = [this.submitButton]; + + // Check if the submit button is initially enabled + const submitInitiallyEnabled = !this.submitButton.attr('disabled'); + + // Filter out buttons that are initially enabled + var initiallyEnabledButtons = buttonsExceptSubmit.filter(function(button) { return !button.attr('disabled'); }); + + if (isFromCheckOperation) { + // Add the submit button to the initially enabled buttons if it was initially enabled + if (submitInitiallyEnabled) { + initiallyEnabledButtons.push(this.submitButton); + } + } else { + // If reset is clicked, disable the submit button if it was initially enabled + if (submitInitiallyEnabled) { + this.enableButtons(submitButtonArr, false, isFromCheckOperation); + } + } this.enableButtons(initiallyEnabledButtons, false, isFromCheckOperation); + return operationCallback().always(function() { - return that.enableButtons(initiallyEnabledButtons, true, isFromCheckOperation); + if (!isFromCheckOperation) { + // Enable the submit button if there is a gentle alert visible + if (that.el.find(".notification-gentle-alert .notification-message:visible").length > 0) { + // Ensure the submit button is added to the initially enabled buttons if it was initially enabled + if (submitInitiallyEnabled) { + initiallyEnabledButtons.push(that.submitButton); + } + } else { + // Otherwise, disable the submit button + that.enableButtons(submitButtonArr, false, isFromCheckOperation); + } + } + // Re-enable all initially enabled buttons + return that.enableButtons(initiallyEnabledButtons, true, isFromCheckOperation); }); + }; /**