Bootstrap selectpicker don't work in remote modal

1.3k views Asked by At

When I use remote Modal, I add class selectpicker to example.php. It don't show result. When I remove select#selectpicker it shows option to select.

<button type="button" class="btn btn-primary" data-toggle="modal"
    href="example.php" data-target="#detail"> Example </button>
<div>q
    <div class="modal fade" id="detail" role="dialog">
        <div class="modal-dialog modal-lg ui-front">
            <div class="modal-content">
            </div>
        </div>
    </div>
</div>

Code example

1

There are 1 answers

0
Shashank On

I don't see a selectpicker initialization in the body. And as the select is being rendered from the .php file, it won't be a part of the DOM until the modal opens up.

So you can initialize the selectpicker as following for it to work: (i.e. once modal shows up):

<script>
$('body div#detail.modal').one('shown.bs.modal', function (e) { 
    $(this).find('div.modal-content select').selectpicker(); 
})
</script>