Skip to content

Commit

Permalink
fix: correctly handles the enabling of submit button on reset
Browse files Browse the repository at this point in the history
- 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 <imasdekar@disroot.org>
  • Loading branch information
imasdekar committed Jul 17, 2024
1 parent 60719bd commit bf4fce0
Showing 1 changed file with 39 additions and 3 deletions.
42 changes: 39 additions & 3 deletions xmodule/js/src/capa/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

};

/**
Expand Down

0 comments on commit bf4fce0

Please sign in to comment.