bootstrap-validator icon indicating copy to clipboard operation
bootstrap-validator copied to clipboard

Select Box

Open CEscorcio opened this issue 7 years ago • 1 comments
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>

CEscorcio avatar Mar 14 '18 13:03 CEscorcio

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

M3ssman avatar Apr 30 '18 14:04 M3ssman