-
Improvement
-
Resolution: Fixed
-
Minor
-
4.2.6
-
MOODLE_402_STABLE
-
MOODLE_404_STABLE
-
MDL-80608-main -
-
When using modal forms, a number of events are available, including ERROR. The ModalForms.ERROR event, according to its documentation, is:
'Error occurred while performing request to the server.'
What it actually does is detect any error during the AJAX call to core_form_dynamic_form when submitting the form. Whoever catches the event can either process and cancel it, or leave it alone in which case Notification.Exception will be called to display the exception.
This is great but there is no way to do anything similar during the AJAX call made to core_form_dynamic_form when originally loading the form - in show() via getBody and setBodyContent, or in processNoSubmitButton(). Both these cases just call Notification.Exception with no event.
Based on the comment on the ERROR event, I think it should be called in both those other cases as well. This would be a slight change in behaviour, so arguably it might be more backwards-compatible to create a different event (DEFINITION_ERROR perhaps). However, if people agree that is not a big concern, then perhaps we can just fix the simple bug - that the in-code documentation currently claims that the ERRROR event is fired for errors while carrying out server requests, but in fact it only sometimes is.
While fixing this I am also going to fix a minor secondary problem, which is that if an exception occurs during submission (that's the one you could already trap), it doesn't re-enable the buttons, so after closing the [default or overridden] exception popup, you can't e.g. change the form contents and resubmit, because all buttons are greyed out.