userfrosting / UserFrosting

Modern PHP user login and management framework
https://www.userfrosting.com
Other
1.64k stars 366 forks source link

[Bug] Default handling for "renderError.ufModal" #1231

Open avsdev-cw opened 1 year ago

avsdev-cw commented 1 year ago

Submitted by request from UF chat.

Applies to both UF4 and UF5.

If a modal causes an error (e.g. permission denied) then trying to repeat the action, or attempt to do any other action which would trigger a modal, without reloading the page does not do anything. This is because the "renderError.ufModal" event is never listened to and ufModal.destroy() is never called.

I managed to add a recursive global listener (required because the ufModal.destroy() method removes all listeners) by doing something like:

$(document).ready(function() {
    const handleModalError = function() {
        $(this).ufModal('destroy');
        $('body').on('renderError.ufModal', handleModalError);
    }
    $('body').on('renderError.ufModal', handleModalError);
});

however it causes a javscript exception (uf-modal.js:146):

Uncaught TypeError: instance is undefined