Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correctly handles the enabling of submit button on reset #35118

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 50 additions & 7 deletions xmodule/js/src/capa/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

(function() {
'use strict';
// constants for denoting the click of submit/save/reset button
var submitClick = "submit";
var saveClick = "save";
var resetClick = "reset";

var indexOfHelper = [].indexOf
|| function(item) {
Expand Down Expand Up @@ -136,6 +140,7 @@
this.url = this.el.data('url');
this.content = this.el.data('content');


// has_timed_out and has_response are used to ensure that
// we wait a minimum of ~ 1s before transitioning the submit
// button from disabled to enabled
Expand Down Expand Up @@ -630,7 +635,7 @@

Problem.prototype.submit = function() {
if (!this.submit_save_waitfor(this.submit_internal)) {
this.disableAllButtonsWhileRunning(this.submit_internal, true);
this.disableAllButtonsWhileRunning(this.submit_internal, true, submitClick);
}
};

Expand Down Expand Up @@ -696,7 +701,7 @@
};

Problem.prototype.reset = function() {
return this.disableAllButtonsWhileRunning(this.reset_internal, false);
return this.disableAllButtonsWhileRunning(this.reset_internal, false, resetClick);
};

Problem.prototype.reset_internal = function() {
Expand Down Expand Up @@ -802,7 +807,7 @@

Problem.prototype.save = function() {
if (!this.submit_save_waitfor(this.save_internal)) {
this.disableAllButtonsWhileRunning(this.save_internal, false);
this.disableAllButtonsWhileRunning(this.save_internal, false, saveClick);
}
};

Expand Down Expand Up @@ -1219,18 +1224,56 @@
* 'operationCallback' is an operation to be run.
* isFromCheckOperation' is a boolean to keep track if 'operationCallback' was
* from submit, if so then text of submit button will be changed as well.
* isWhichOperation' is a string to keep track if 'operationCallback' was
* from submit/reset/save, if so then handle the submit button enabling/disabling accordingly.
*
*/
Problem.prototype.disableAllButtonsWhileRunning = function(operationCallback, isFromCheckOperation) {
Problem.prototype.disableAllButtonsWhileRunning = function(operationCallback, isFromCheckOperation, isWhichOperation) {
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 ((isWhichOperation === submitClick) || (isWhichOperation === saveClick)) {
// Add the submit button to the initially enabled buttons if it was initially enabled
if (submitInitiallyEnabled) {
initiallyEnabledButtons.push(this.submitButton);
}
} else if (isWhichOperation === resetClick) {
// 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 (isWhichOperation === resetClick) {
// 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
Loading