Modal forms: addEventListener to modalForm.events.FORM_CANCELLED

Modal forms: addEventListener to modalForm.events.FORM_CANCELLED

by Eiz Eddin Al Katrib -
Number of replies: 0
Picture of Core developers Picture of Plugin developers

Hi,

I'm following this guide to add a modal form to a Moodle 3.11 site:

https://docs.moodle.org/dev/Modal_and_AJAX_forms

Everything seems working fine so far, however, I cannot figure out how I can add an event listener to the FORM_CANCELLED event. And I could not actually find such event listener implemented anywhere in the code of 3.11!

I'm using the following code:

-------------

modalForm.addEventListener(modalForm.events.FORM_SUBMITTED, e => {
                const response = e.detail;
                console.log(response);
            });

modalForm.addEventListener(modalForm.events.FORM_CANCELLED, e => {
                console.log('canceled!');
                window.location.reload();
            });

-----------

The FORM_SUBMITTED event listener is working fine. But not the FORM_CANCELLED. Nothing happens when the modal form is canceled.

I appreciate any help.

Average of ratings: -