3

I have a JQuery UI modal that renders a partial MVC view if certain qualifiers exist. In my JavaScript, I only want the form to submit after the modal completes. This is what I have:

$('#btnSaveAndSend').click(function (e) {
        var result = _fieldsAreValid($('#validation').val() === "y");

        if (result) {

            if (showPrompt) {
                $('#divPrompt').dialog({
                    autoOpen: true,
                    width: 500,
                    height: 225,
                    modal: true,
                    draggable: false,
                    resizable: false,
                    title: "Modal",
                    open: function (event, ui) {
                        $(this).load("/Home/SendEmail");
                    }
                });
            }
            $("#form").submit();               
        }
    });

Without AJAX, is there any way to do this?

1 Answer 1

3

Using a promise for the parent's to check for its completion should do the trick. try replacing your open with this:

open: function (event, ui) {
    $(this).parent().promise().done(function () {
       $("#form").submit();
    });
}
Sign up to request clarification or add additional context in comments.

3 Comments

I would assume that would occur after the .load line?
doesn't really matter, you're just adding a listener to the done event
The parent in this case is actually the open event, not detecting that the window has closed and the form has been submitted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.