Reputation: 352
I am implementing this selectpicker for my website. I encountered an issue that an element that has the selectpicker
class it doesn't show on my DOM.
here is the code
<div id="modal-container" class="modal fade hidden-print" tabindex="-1" role="dialog" data-backdrop="static" data-keyboard="false">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Add New Experience</h4>
</div>
<div id="addExperience" class="modal-body">
<div class="form-horizontal">
<div class="form-group">
<div class="col-md-12">
<select class="user-form selectpicker show-tick form-control" data-live-search="true">
<option>A</option>
</select>
</div>
</div>
</div>
</div>
</div>
</div>
please help me get in track with my development.
Thanks!
Upvotes: 3
Views: 20175
Reputation: 101
You have 2 options;
Firstly add this options in your select tag;
<select ... data-container="body"> ... </select>
source: docs
Secondly write this code for override "overtflow" property
.modal-content{
overflow: unset;
}
Upvotes: 0
Reputation: 161
You have to reinitialize your Bootstrap-Select (.selectpicker) after loading your modal. The reason why this is happening is, your modal is a newly created element and your selectpicker is not yet initialized on it.
Here's my code:
// Create
$(document).on('click', '.add', function()
{
$.ajax({
type: 'GET',
url: 'suppliers/create',
dataType: 'json',
success: function(data)
{
modal.find('.modal-title').html(data.title);
modal.find('.modal-body').html(data.body);
$('.selectpicker').selectpicker();
}
});
modal.modal('show');
});
Thanks very much to Cerlin Boss for this solution!
Upvotes: 8
Reputation: 9794
You need to add the below required resources in your plunker example
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js">
</script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.1/css/bootstrap-select.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.1/js/bootstrap-select.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.1/js/i18n/defaults-en_US.js"></script>
and things work fine :)
Let me know in case the actual code still differs from the plunker.
Example : https://plnkr.co/edit/4gJBAu3NKUQp1HMUbrK9?p=preview
Upvotes: 2