Boostrap select box / dropdowns

Just looking at development with Bootstrap for the first time and think I'm suffering from Bootstrap'itis - trying to over Boostrapify things perhaps?

I need traditional drop down select boxes, i.e. I select an item from the list to filter a set of results and that item then becomes the selected value in the list on the refresh.

Can I do this easily with a Bootstrap dropdown? I'm struggling with how I get the currently selected element to be visible without having to drop the box down again.
 

sausagecoma

Wise, Aged Ars Veteran
115
Short answer: Bootstrap won't allow you to accomplish this.

It sounds like you're dealing with postback (https://stackoverflow.com/questions/183254/what-is-a-postback) and your drop down is being reset to its default selection. This would be the case if you're using a html form and your drop down triggers a submit.a page refresh is different than a postback, though. So you may need to clarify.

Getting the value that was selected before the postback/refresh will depend on what tech you're using (asp.net, plain old browser etc.)
 

Jehos

Ars Legatus Legionis
55,560
You're using the wrong control, you're describing the behavior of a select control in a form.

https://getbootstrap.com/docs/4.0/components/forms/

Bootstrap Dropdowns are menus, not selects. Ok, they're not *technically* menus, but they're like the Debug button in Visual Studio. Use them for multi-mode action buttons, not choosing things from a list.

Here's the Debug toolbar in VS:

clipboard07.jpg


The "Debug" and "Any CPU" would be Selects. You can change their value and the value change sticks. The "Attach to Unity" is a Dropdown (technically a split dropdown)--it *always* says "Attach to Unity", but you can click the arrow to choose additional one-shot actions for the button to do. No matter what you pick though, it always says "Attach to Unity".
 

krimhorn

Ars Legatus Legionis
39,865
Many thanks. Yep, gone back to a standard select - I think I was getting carried away with Bootstrap, all the examples were using dropdowns as simple selects and it was throwing me.
Bootstrap's select* is just a class that restyles the HTML select if you give it the class 'form-control'.

*ignore the "input" in the URL, the Bootstrap site's shitty persistent banner occludes the page content at the id in the URL. The select should be the first control visible on the page.