Select2 inside Bootstrap Modal does not size properly and search does not work
See original GitHub issueHaving the following HTML
<form id="frmFoo" ...>
<div class="form-group">
<label for="txtFoo" class="col-sm-2 control-label">Foo Field :</label>
<div class="col-sm-6">
<select id="txtFoo" class="form-control" placeholder="Foo Value"></select>
</div>
</div>
</div>
</form>
will not display the <select>
element’s width properly as the form-control
class is completely ignored when generating the widget’s UI.
** Edit **
Also, there are other discrepancies with Bootstrap’s UI, such as the focus’ borders, that are not respected and cause inconsistent UI.
Issue Analytics
- State:
- Created 9 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Common problems - The jQuery replacement for select boxes
Select2 does not function properly when I use it inside a Bootstrap modal. ... This issue occurs because Bootstrap modals tend to steal...
Read more >Select2 doesn't work when embedded in a bootstrap modal
According to the official select2 documentation this issue occurs because Bootstrap modals tend to steal focus from other elements outside of the ...
Read more >Select 2 search not clickable in Bootstrap modal - Okler Themes
with select2 inside them. The search field in the select2 isn't clickable so the users can't search within the rows of the select....
Read more >Select 2 drop-down input search doesn't work inside bootstrap ...
By removing the " tabindex " attribute from the modal. This will allow moving around in the Select2 box, but you lose the...
Read more >Dropdown is not reachable when element is rendered in modal
Another issue is that when the select2 JS attach behavior runs, the jQuery dialog is not a selectable element with $('.ui-modal') when trying...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The solution is to document
dropdownParent
for the dropdown input search issue. As for the width, I’m not sure what would be the proper way (I have not dug into the sources much since the last major release).At the moment, I temporarily fix this by manually setting
width: 100%;
to the<select>
element.It just hit me that this is already documented.
https://select2.github.io/options.html#dropdownParent
The Bootstrap issue is pretty well documented at https://github.com/select2/select2/issues/600.