MDL-76848 core: add disable buttons to modals

This commit is contained in:
Ferran Recio 2023-01-17 18:29:00 +01:00
parent 8503f2cfd8
commit b1ad8480fe
4 changed files with 24 additions and 2 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1008,5 +1008,24 @@ define([
this.focusOnClose = element;
};
/**
* Set the a button enabled or disabled.
*
* @param {DOMString} action The action of the button
* @param {Boolean} disabled the new disabled value
*/
Modal.prototype.setButtonDisabled = function(action, disabled) {
const button = this.getFooter().find(this.getActionSelector(action));
if (!button) {
throw new Error("Unable to find the '" + action + "' button");
}
if (disabled) {
button.attr('disabled', '');
} else {
button.removeAttr('disabled');
}
};
return Modal;
});

View File

@ -62,6 +62,9 @@ information provided here is intended especially for developers.
description being incorrectly passed for the $required parameter). A debugging notice will be shown when such cases occur.
* The moodle-core-popuphelp YUI modal has been removed. It has not been actively used in Moodle since 3.3. It should be replaced with appropriate ESM/AMD JavaScript.
* The moodle-core-tooltip YUI modal has been removed. It should be replaced with appropriate ESM/AMD JavaScript.
* The core/modal module and all their versions (SAVE_CANCEL, DELETE_CANCEL...) now has a setButtonDisable to disable or enable
specific modal action buttons. This function allows developers to have modals that could only be submited if the user do some
action in the modal body like ticking a checkbox or selecting an element.
=== 4.1 ===