I have a select which I am trying to use with bootstrap 3 by using the selectpicker
class. I want to be able to get the data from the option the user selects so I'm using the jquery onchange
for my selectpicker
. I'm pretty confident with finding the selected value and what not from a regular select but when the html gets rendered for the bootstrap selectpicker, it's done differently. My original select gets a display: none;
style added to it and then it generates a ssecond div containing all my option items.
Here is my select in my template:
<select id="buildings" class="selectpicker" data-width="80%" data-live-search="true" style="border-radius:0px;" >
{% for category in building_categories %}
<optgroup label="{{ category.asBuildingCategory }}">
{% for building in buildings %}
<option data-content="<span data-latitude='{{building.building.decLatitude}}' data-longitude='{{building.building.decLongitude}}' data-build-id='{{building.building.ixBuilding}}'>{{building.building.asBuilding}}</span>"></option>
{% endfor %}
</optgroup>
{% endfor %}
</select>
I have to add a data-content
since bootstrap selectpicker won't have my custom data elements after it's rendered its own way.
Now I've seen someone else has done pretty much what I'm doing except mine just won't work. Bootstrap-select - how to fire event on change. The value returned is simply "" because I'm assuming it has something to do with my select
getting a display: none;
added