The Bootsrap-select plugin is amazing (http://silviomoreto.github.io/bootstrap-select/). It provides an extremely easy way of creating gorgeous select menus in Bootstrap. The one problem I've encountered with it, however, is "flickering" on page load. What I mean by this is fairly straight forward:
So, the user first sees the HTML select element and then sees it switch to the pretty Bootstrap-select item, thus the "flickering".
Has anyone found a good solution to the problem?
Bootstrap-select requires jQuery v1.8.0+, Bootstrap’s dropdown.js component, and Bootstrap’s CSS. The plugin can be imported directly in your project from the CDN (links on the official site). You have to import a CSS file to style the select boxes and a Javascript file to make the entire thing work.
When having to add a select picker, the first option is the default Bootstrap 4 component. This will not style the dropdown menu where the options appear though. Another popular option is to create your own classes and add them to the <select> tag for restyling.
1. Bootstrap-select by Silvio Moreto. The first plugin that can help us add custom styles and additional functionalities to our Bootstrap select input fields is called “Bootstrap-select”. It’s a jQuery plugin that uses Bootstrap’s dropdown.js library.
The Boostrap Select Picker plugin is a library for supporting work with select inputs. The basic setup will show a simple select box and the styling for the dropdown will be the same as the one for the Bootstrap 4 dropdown. This is a plus, since your design will be consistent across your project.
The best and most simple answer:
Add the existing Bootstrap class invisible
to your Select object on the markup page, whether it's an HTML Input element or HTML Select element: https://getbootstrap.com/docs/5.1/utilities/visibility/
e.g.
<input class="visible">...</div>
<input class="invisible">...</div>
This prevents the HTML version of the Select/DDL from being visible to the user, while reserving the space in the layout that the SELECT would take up (which is rendered in once the bootstrap-select JS is initialized).
This solution works for me:
<select class="selectpicker">
<option>Option 1</option>
<option>Option 2</option>
<option>Option 3</option>
<option>Option 4</option>
</select>
<script>
$('.selectpicker').selectpicker({
width: '100%'
});
</script>
I just place the script right after the creation of the select drop-down, instead of waiting for the document to be ready!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With