Link to home
Start Free TrialLog in
Avatar of Daniel Pineault
Daniel Pineault

asked on

Reopen modal buttons no longer work?

I'm struggling to close a modal window and then reopen it.

Upon submitting a modal I use

$('form#{$model->formName()}').on('beforeSubmit', function(e){
    var \$form = $(this);
    $.post(
        \$form.attr("action"), //serialize Yii2 form 
        \$form.serialize()
    )

    .done(function(result){
        //console.log(result);
        result = JSON.parse(result);
        if(result.status == 'Success'){
            $(\$form).trigger("reset");
            // $.pjax.reload({container:'#InvoiceItemsListGrid'}); //Does not work and reloads the main page, not the modal window?!
            $("#closeButton3").click(); //Close the 3rd modal
            $("#closeButton2").click(); //Close the 2nd modal
            $("#"+$('#modalPopup2 #passInfo #refBtn').val()).click(); //re-open the 2nd modal by clicking on the appro button to refresh the info
        }else{
            $(\$form).trigger("reset");
            $("#message").html(result.message);
        }
    })

    .fail(function(){
        console.log("server error");
    });

    return false;
});

Open in new window


Now, although not the way I wanted to handle this, it does work in a general sense.  It closes the 2 modal windows and then reopens the second one displaying the submission.  The issue I'm facing is that if I close the modal and then reopen it, none of the buttons works.  They all loose their event and I don't get why?

I've been at this for 2 days and just can't figure it out.  I've tried all sorts of things.

Thank you in advance.
ASKER CERTIFIED SOLUTION
Avatar of Alfredo Luis Torres Serrano
Alfredo Luis Torres Serrano
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Daniel Pineault
Daniel Pineault

ASKER

I can't thank you both enough!

I was doing
$(function(){
    $('.showModal3').click(
        function (){
            ...
        }
    );
});

Open in new window


I thought the above did the same thing, but obviously not as by using
$(document).on("click", '.CloseMe', function(event) { 
     ...
 });

Open in new window

works perfectly.
You're welcome sir, glad we could help.