Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a Bootstrap dropdown required?

Tags:

So, I've got following code for a dropdown box made with bootstrap:

<div class="btn-group">     <button id="landKapitein" type="button" data-toggle="dropdown" class="btn btn-default dropdown-toggle">Land         <span class="caret"></span>     </button>     <ul class="dropdown-menu">         <li><a role="menuitem" tabindex="-1" href="#">België/Belgique</a></li>         <li><a role="menuitem" tabindex="-1" href="#">Deutschland</a></li>         <li><a role="menuitem" tabindex="-1" href="#">France</a></li>         <li><a role="menuitem" tabindex="-1" href="#">Nederland</a></li>         <li><a role="menuitem" tabindex="-1" href="#">United Kingdom</a></li>      </ul> </div> 

Now I want to make it required to select something from this dropdown box before you can continue on. I've already done this for textboxes and radio buttons by just adding required to the tag, but I don't have a tag like that here, so how do I do this then?

like image 887
Venser Avatar asked Mar 08 '15 14:03

Venser


People also ask

How Bootstrap dropdown is implemented?

To open the dropdown menu, use a button or a link with a class of . dropdown-toggle and the data-toggle="dropdown" attribute. The . caret class creates a caret arrow icon (), which indicates that the button is a dropdown.

How set dropdown position in Bootstrap?

By default, a dropdown menu is automatically positioned 100% from the top and along the left side of its parent. Add . dropdown-menu-right to a . dropdown-menu to right align the dropdown menu.

How can create hover dropdown in Bootstrap?

Answer: Use the jQuery hover() method By default, to open or display the dropdown menu in Bootstrap you have to click on the trigger element. However, if you want to show the dropdown on mouseover instead of click you can do it with little customization using the CSS and jQuery.


1 Answers

If we just put required in select tag and <option value="">None</option> in the option it will work for validation. I have refer this page.

It works for selection must be made among provided value.

But I would like to know how to write custom validation message coming by default like this message.? enter image description here

 <form action="demo_form.asp">     <select required>       <option value="">None</option>       <option value="volvo">Volvo</option>       <option value="saab">Saab</option>       <option value="mercedes">Mercedes</option>       <option value="audi">Audi</option>     </select>     <input type="submit">     </form> 

Above code works fine for validation like "Selecting an item in the list before submit".

like image 138
Gautam Avatar answered Oct 07 '22 00:10

Gautam