O
O
oxfree2016-06-22 04:17:00
Yii
oxfree, 2016-06-22 04:17:00

Bootstrap modal only loads content once. What is the problem?

Links that call the modal window

<a data-toggle="modal"
           data-target="#a-modal"
           href="<?=Url::to(['/admin/buildings/update','id'=>1])?>"
            ><span class="glyphicon glyphicon-cog"></span></a>

        <a data-toggle="modal"
           data-target="#a-modal"
           href="<?=Url::to(['/admin/buildings/update','id'=>2])?>"
            ><span class="glyphicon glyphicon-cog"></span></a>

The modal window itself
<div class="modal fade" tabindex="-1" role="dialog" aria-hidden="true" id="a-modal">
        <div class="modal-dialog modal-lg">
            <div class="modal-content">
            </div>
        </div>
    </div>

Clicking on any link in the modal window loads the content, clicking on the next link opens the modal window with what was loaded from the previous link.
I implemented such a crooked solution, but it's really bad:
$("#a-modal").on("show.bs.modal", function(e) {
        var link = $(e.relatedTarget);
        $(this).find(".modal-content").load(link.attr("href"));
    });

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Klyuev, 2016-06-22
@oxfree

There was a similar problem in the 1st project. Solved it like this:

jQuery(document).ready(function () {
    $('.modal').on('hidden.bs.modal', function (e) {
        $(this).removeData('bs.modal');
    });
});

Now this code wanders from project to project))) It was a long time ago, maybe something has already changed at the moment.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question