saribe / eModal

Easy Modal for bootstrap, is a simple way to create modal dialogs using javascript.
http://saribe.github.io/eModal
271 stars 97 forks source link

Dynamic load scripts not working with eModal. #83

Closed sinanbozkus closed 5 years ago

sinanbozkus commented 6 years ago

I'm using eModal with a Partial View (ASP.NET Core). And I'm calling the partial view like that.

My main page:

var btnSample= $("#txtBtnSample");
        btnSample.on("click",
            function() {
                var options = {
                    buttons: [
                        { text: 'Cancel', close: true, style: 'danger' },
                        { text: 'Save', close: false, style: 'primary', click: SaveFunction }
                    ],
                    size: eModal.size.lg,
                    title: "Sample Title",
                    url: "http://sampleurl"
                };
            return eModal.ajax(options);
        });

I have some javascript codes at the end of the partial view. (sending an ajax request etc.) These codes are generally working at the first request. If I refresh the page and open the modal again, these codes don't work anymore.

My partial:

<form id="SampleForm" method="post">

    <input type="hidden" asp-for="Id" />

    <div class="form-group row">
        <label asp-for="SampleProperty" class="col-sm-2 col-form-label"></label>
        <div class="col-sm-4">
            <input type="text" asp-for="SampleProperty" class="form-control">
            <span asp-validation-for="SampleProperty" class="form-text m-b-none text-danger"></span>
        </div>
</form>

<script>
// some javascript codes like submit the form with ajax request.
</script>
sinanbozkus commented 6 years ago

If I use a bootstrap modal with jquery load, there is no problem. The problem is because of the eModal.

acantophis commented 6 years ago

I have same problem - it works after refresh page but after I go to other page and back (with hashtag) it doesn't work any more.

saribe commented 5 years ago

I not sure about all implementation, but regarding what I can see, we are attaching to the element that will be replaced when refresh!

var btnSample= $("#txtBtnSample");

btnSample is not in the dom anymore!