mirror of
https://github.com/moodle/moodle.git
synced 2025-07-23 15:22:05 +02:00
MDL-64331 modals: Be careful closing modals
Don't close a modal when the user clicks outside of it and the modal contains a form.
This commit is contained in:
@@ -35,6 +35,7 @@ define(['jquery', 'core/templates', 'core/notification', 'core/key_codes',
|
||||
FOOTER: '[data-region="footer"]',
|
||||
HIDE: '[data-action="hide"]',
|
||||
DIALOG: '[role=dialog]',
|
||||
FORM: 'form',
|
||||
MENU_BAR: '[role=menubar]',
|
||||
HAS_Z_INDEX: '.moodle-has-zindex',
|
||||
CAN_RECEIVE_FOCUS: 'input:not([type="hidden"]), a[href], button, textarea, select, [tabindex]',
|
||||
@@ -571,6 +572,18 @@ define(['jquery', 'core/templates', 'core/notification', 'core/key_codes',
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
/**
|
||||
* Hide this modal if it does not contain a form.
|
||||
*
|
||||
* @method hideIfNotForm
|
||||
*/
|
||||
Modal.prototype.hideIfNotForm = function() {
|
||||
var formElement = this.modal.find(SELECTORS.FORM);
|
||||
if (formElement.length == 0) {
|
||||
this.hide();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Hide this modal.
|
||||
*
|
||||
@@ -727,7 +740,7 @@ define(['jquery', 'core/templates', 'core/notification', 'core/key_codes',
|
||||
// So, we check if we can still find the container element or not. If not, then the DOM tree is changed.
|
||||
// It's best not to hide the modal in that case.
|
||||
if ($(e.target).closest(SELECTORS.CONTAINER).length) {
|
||||
this.hide();
|
||||
this.hideIfNotForm();
|
||||
}
|
||||
}
|
||||
}.bind(this));
|
||||
|
Reference in New Issue
Block a user