mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 05:58:34 +01:00
MDL-70962 forms: catch modal exceptions when getting body content.
They are thrown in the following circumstances: * The dynamic form class doesn't exist; * It does exist but it's `check_access` method throws exception Co-Authored-By: Andrew Nicols <andrew@nicols.co.uk>
This commit is contained in:
parent
4c26696e7e
commit
11099c15bb
2
lib/amd/build/modal.min.js
vendored
2
lib/amd/build/modal.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -456,7 +456,11 @@ define([
|
||||
// This is a non-spec feature of jQuery and cannot be produced with spec promises.
|
||||
// We can encourage people to migrate to this approach, and in future we can swap
|
||||
// it so that setBody() calls setBodyPromise().
|
||||
return promise.then(({html, js}) => this.setBody($.when(html, js)));
|
||||
return promise.then(({html, js}) => this.setBody($.when(html, js)))
|
||||
.catch(exception => {
|
||||
this.hide();
|
||||
throw exception;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
|
2
lib/form/amd/build/modalform.min.js
vendored
2
lib/form/amd/build/modalform.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -124,7 +124,9 @@ export default class ModalForm {
|
||||
// we need to make sure that the modal already exists when we render the form. Some form elements
|
||||
// such as date_selector inspect the existing elements on the page to find the highest z-index.
|
||||
const formParams = new URLSearchParams(Object.entries(this.config.args || {}));
|
||||
this.modal.setBodyContent(this.getBody(formParams.toString()));
|
||||
const bodyContent = this.getBody(formParams.toString());
|
||||
this.modal.setBodyContent(bodyContent);
|
||||
bodyContent.catch(Notification.exception);
|
||||
|
||||
// After successfull submit, when we press "Cancel" or close the dialogue by clicking on X in the top right corner.
|
||||
this.modal.getRoot().on(ModalEvents.hidden, () => {
|
||||
@ -270,8 +272,12 @@ export default class ModalForm {
|
||||
notifyResetFormChanges() {
|
||||
return new Promise(resolve => {
|
||||
Y.use('event', 'moodle-core-event', 'moodle-core-formchangechecker', () => {
|
||||
Event.notifyFormSubmitAjax(this.modal.getRoot().find('form')[0], true);
|
||||
// Ensure that modal contains a form element (it may not if the form class threw an early exception).
|
||||
const form = this.modal.getRoot().find('form')[0];
|
||||
if (form) {
|
||||
Event.notifyFormSubmitAjax(form, true);
|
||||
M.core_formchangechecker.reset_form_dirty_state();
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
@ -307,7 +313,11 @@ export default class ModalForm {
|
||||
let formData = this.modal.getRoot().find('form').serialize();
|
||||
formData = formData + '&' + encodeURIComponent(button.getAttribute('name')) + '=' +
|
||||
encodeURIComponent(button.getAttribute('value'));
|
||||
this.modal.setBodyContent(this.getBody(formData));
|
||||
|
||||
const bodyContent = this.getBody(formData);
|
||||
this.modal.setBodyContent(bodyContent);
|
||||
bodyContent.catch(Notification.exception);
|
||||
|
||||
return null;
|
||||
})
|
||||
.catch(null);
|
||||
|
Loading…
x
Reference in New Issue
Block a user