($width) AND $width .= 'px'; $style = " style=\"width: $width\""; } $value = $value ? $value : date('H:i'); $s = ""; return $s; } // form_date('start', '2018-07-05') 为空则当前日期 function form_date($name, $value = 0, $width = FALSE) { $style = ''; if (FALSE !== $width) { is_numeric($width) AND $width .= 'px'; $style = " style=\"width: $width\""; } $value = $value ? $value : date('Y-m-d'); $s = ""; return $s; } /**用法 * * echo form_radio_yes_no('radio1', 0); * echo form_checkbox('aaa', array('无', '有'), 0); * * echo form_radio_yes_no('aaa', 0); * echo form_radio('aaa', array('无', '有'), 0); * echo form_radio('aaa', array('a'=>'aaa', 'b'=>'bbb', 'c'=>'ccc', ), 'b'); * * echo form_select('aaa', array('a'=>'aaa', 'b'=>'bbb', 'c'=>'ccc', ), 'a'); */ ?>javascript - bootstrap validator with bootstrap select not working - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - bootstrap validator with bootstrap select not working - Stack Overflow

programmeradmin0浏览0评论

I have a form with few input fields and select menus. I'm using bootstrap select plugin for select menus. Link So I just pleted all things and applied bootstrap validation using this plugin. Link and it's working fine except select menus.

When I click the select menu and click out side ( without selecting menu items ) It didn't do anything. Normally it should change border color and give error message like this. "Please fill out this field." But when I click submit, it working fine. After that I removed bootstrap selectpicker plugin. Then it worked fine. I'm thinking that there are conflicts with both two plugins. Please see example images.

Click select menu and outside click(not working)

Click form submit and working fine.

And I tried with this code but no luck. I need to show an error message when someone click select menu and if he doesn't choose anything and click outside like input fields. What is the best solution for this?

Here is an example jsbin

<form data-toggle="validator">
    <div class="form-group">
      <label for="select" class="control-label">Title</label>
         <div class="form-input">
           <select class="selectpicker form-control" title="Please Select" id="select" name="select" required>
             <option value=""></option>
             <option value="1">Mr</option>
             <option value="2">Mrs</option>
             <option value="3">Ms</option>
             <option value="4">Miss</option>
             <option value="5">Dr</option>
           </select>
        <div class="help-block with-errors"></div>
      </div>
    <div class="form-group">
      <button type="submit" class="btn btn-primary">Submit</button>
    </div>
  </form>

$('.select').on( 'hide.bs.select', function ( ) {
    $(this).trigger("focusout");
});

I have a form with few input fields and select menus. I'm using bootstrap select plugin for select menus. Link So I just pleted all things and applied bootstrap validation using this plugin. Link and it's working fine except select menus.

When I click the select menu and click out side ( without selecting menu items ) It didn't do anything. Normally it should change border color and give error message like this. "Please fill out this field." But when I click submit, it working fine. After that I removed bootstrap selectpicker plugin. Then it worked fine. I'm thinking that there are conflicts with both two plugins. Please see example images.

Click select menu and outside click(not working)

Click form submit and working fine.

And I tried with this code but no luck. I need to show an error message when someone click select menu and if he doesn't choose anything and click outside like input fields. What is the best solution for this?

Here is an example jsbin

<form data-toggle="validator">
    <div class="form-group">
      <label for="select" class="control-label">Title</label>
         <div class="form-input">
           <select class="selectpicker form-control" title="Please Select" id="select" name="select" required>
             <option value=""></option>
             <option value="1">Mr</option>
             <option value="2">Mrs</option>
             <option value="3">Ms</option>
             <option value="4">Miss</option>
             <option value="5">Dr</option>
           </select>
        <div class="help-block with-errors"></div>
      </div>
    <div class="form-group">
      <button type="submit" class="btn btn-primary">Submit</button>
    </div>
  </form>

$('.select').on( 'hide.bs.select', function ( ) {
    $(this).trigger("focusout");
});
Share Improve this question asked Jul 19, 2017 at 10:10 user6037606user6037606
Add a ment  | 

2 Answers 2

Reset to default 3

You are handling the hide.bs.select event on the select class that is not on your select input. Try with .selectpicker instead :

<form data-toggle="validator">
    <div class="form-group">
      <label for="select" class="control-label">Title</label>
         <div class="form-input">
           <select class="selectpicker form-control" title="Please Select" id="select" name="select" required>
             <option value=""></option>
             <option value="1">Mr</option>
             <option value="2">Mrs</option>
             <option value="3">Ms</option>
             <option value="4">Miss</option>
             <option value="5">Dr</option>
           </select>
        <div class="help-block with-errors"></div>
      </div>
    <div class="form-group">
      <button type="submit" class="btn btn-primary">Submit</button>
    </div>
  </form>

$('.selectpicker').on( 'hide.bs.select', function ( ) {
    $(this).trigger("focusout");
});

Here is the updated jsbin

You have to use ".selectpicker".

Maybe it will helps you to solve yout issue:

http://formvalidation.io/examples/bootstrap-select/

发布评论