bootstrap-validator
bootstrap-validator copied to clipboard
Select Box
trafficstars
How can the validation work in selection option? I have the follow code, and i want the get an validation error if i dont choose any shop.
<select name="place" class="form-control" required="required" data-error="Pick ur favorite shop">
<option value="">Pick ur place</option>
<option value="BR">Braga</option>
<option value="FR">Faro</option>
<option value="LR">Leiria</option>
<option value="LX">Lisboa
<option value="PT">Porto</option>
</select>
<div class="help-block with-errors"></div>
Hello!
I managed a similar case by using custom validations:
let opts = {
custom: {
my_select_valiadator: function ($el) {
if($el.val() == "" ) {
return "please select something!";
}
}
};
$("select").validate(opts);
and then add to your inspected select element the attribute "data-my_select_validator="my_select_validator"
Greetings