bootstrap-select: Duplicate selectpicker with turbolinks
Using turbolinks 5, I am observing duplicate pickers when playing with the browser history

I am using a global $('.selectpicker').selectpicker('refresh');
The pickers are actually nesting into each other
<div class="btn-group bootstrap-select caret">
<button class="btn dropdown-toggle btn-default" data-toggle="dropdown" type="button" data-id="sort_type" title="Trier par pertinence" aria-expanded="false">
<div class="dropdown-menu open">
<div class="btn-group bootstrap-select caret">
<button class="btn dropdown-toggle btn-default" data-toggle="dropdown" type="button" data-id="sort_type" title="Trier par pertinence" aria-expanded="false">
<div class="dropdown-menu open">
<div class="btn-group bootstrap-select caret">
<button class="btn dropdown-toggle btn-default" data-toggle="dropdown" type="button" data-id="sort_type" title="Trier par pertinence" aria-expanded="false">
<div class="dropdown-menu open">
<div class="btn-group bootstrap-select caret">
<button class="btn dropdown-toggle btn-default" data-toggle="dropdown" type="button" data-id="sort_type" title="Trier par pertinence">
<div class="dropdown-menu open">
<select id="sort_type" class="caret selectpicker" name="sort_type" tabindex="-98">
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 1
- Comments: 17
My solution:
2019 and no fix for this?
I was able to get around this altogether by invoking the plugin this way:
This preserves the auto-initialization behavior described in the README:
OK, found a temporary(?) solution to this problem, needed to replace the contents of .bootstrap-select with .selectpicker then re-initialise selectpicker:
https://github.com/aperkins81/turbolinks-5-selectpicker/commit/9385f447ac37874b0532d35deb575d089a11f5c5
A simple fix will just select the selectpickers which do not have the
bootstrap-selectclass as direct parent