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); }); + }; /**