Bootstrap表单验证不能处理日期的数字字段集

时间:2016-03-25 10:26:03

标签: twitter-bootstrap validation bootstrapvalidator

我有三个日期字段:

<div class="col-xs-12 form-group col-sm-6">
  <div class="row">
    <div class="col-xs-3">
      <input autocomplete="off" class="form-control birth-day" id="dan_rodjenja" name="dan_rodjenja" max="31" min="1" placeholder="DD" required type="number" value="" />
    </div>
    <div class="col-xs-3">
      <input autocomplete="off" class="form-control birth-month" id="mjesec_rodjenja" max="12" min="1" name="mjesec_rodjenja" placeholder="MM" required type="number" value="" />
    </div>
    <div class="col-xs-6">
      <input autocomplete="off" class="form-control birth-year" id="godina_rodjenja" max="2000" min="1910" name="godina_rodjenja" placeholder="GGGG" required type="number" value="" />
    </div>
 </div>  

例如,如果填充第一个和第二个字段而第三个字段为空,则不会出现任何错误(没有红色边框)。或者当我将第一个字段留空时,所有三个字段都显示错误。有人可以帮我这个吗?

我正在使用bootstrap验证http://1000hz.github.io/bootstrap-validator/

1 个答案:

答案 0 :(得分:1)

div元素,即输入元素的直接父元素,类.form-control必须具有类.form-group(如下面的结构所示​​)。

<div class="form-group">
    <input class="form-control" ... />
</div>

所以你的代码看起来像这样:

<div class="col-xs-12 col-sm-6">
    <div class="row">
        <div class="form-group col-xs-3">
            <input autocomplete="off" class="form-control birth-day" id="dan_rodjenja" name="dan_rodjenja" max="31" min="1" placeholder="DD" required type="number" value="" />
        </div>

        <div class="form-group col-xs-3">
             <input autocomplete="off" class="form-control birth-month" id="mjesec_rodjenja" max="12" min="1" name="mjesec_rodjenja" placeholder="MM" required type="number" value="" />
        </div>

        <div class="form-group col-xs-6">
            <input autocomplete="off" class="form-control birth-year" id="godina_rodjenja" max="2000" min="1910" name="godina_rodjenja" placeholder="GGGG" required type="number" value="" />
        </div>
    </div> 
</div>