Bootstrap 验证 |复选框数据切换="toggle"

Bootstrap Validation | Checkbox data-toggle="toggle"

我想对具有切换效果的复选框应用验证

 <div class="togglebutton form-group has-feedback paddingTopBtn8">
    Yes<label> <input type="checkbox" ng-model="checkfield" required data-error="This is an mandatory field">
   <div class="help-block with-errors"></div>
   <span class="toggle"></span></label>No
</div>

谁能帮帮我。它不工作。我也应用了 required 和 data-error 但在提交表单时显示 ng-valid 无论我是否选中复选框

提前致谢

我想你只需要:

 <input type="checkbox" ng-model="checkfield" required data-error="This is an mandatory field" checked data-toggle="toggle" data-on="Yes" data-off="No" data-onstyle="success" data-offstyle="danger">

我不是很清楚你所说的带复选框的切换效果是什么意思。

但我利用了 https://scotch.io/tutorials/angularjs-form-validation 的表单验证示例,并创建了一个用于复选框验证的小型 POC。

请看这里。

 <div class="togglebutton form-group has-feedback paddingTopBtn8">
    Yes<label> <input type="checkbox" ng-model="user.checkfield" required    
    name="checkfield">
    <p ng-show="userForm.checkfield.$invalid && !userForm.checkfield.$pristine"   
    class="help-block">Please toggle.</p>
    <span class="toggle"></span></label>No
</div>

CodePen Example