Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent modal from closing based on condition #312

Open
ibrahimoguzhany opened this issue Jul 3, 2024 · 0 comments
Open

Prevent modal from closing based on condition #312

ibrahimoguzhany opened this issue Jul 3, 2024 · 0 comments

Comments

@ibrahimoguzhany
Copy link

I need to prevent the user from closing the modal if they have made changes to the form inside the modal (or based on some logic). I've been unable to find a way to achieve this. Is it possible to prevent the modal from closing and show another modal?

$(document).on('modal:before-close', function(event, modal) {
    if ($(modal).is('.modal') && $('#updateProfileForm').length && !pendingModalClose) {
        const currentFormState = $('#updateProfileForm').serialize();
        if (initialFormState !== currentFormState) {
            event.preventDefault(); // doesn't work
            pendingModalClose = true;
            $("#unsavedChangesModal").modal({
                fadeDuration: 250,
                escapeClose: false,
                clickClose: false,
                showClose: false
            });
        }
    }
});
$(document).on('modal:before-close', function(event, modal) {
    $("#unsavedChangesModal").modal({
    fadeDuration: 250,
    escapeClose: false,
    clickClose: false,
    showClose: false
});

When I do this, it automatically closes the main modal, which is something I do not want. I want to show the warning modal on top of my main modal. Can you help, please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant