如何同时使用bootstap4 toogle按钮和jquery验证插件

时间:2019-05-21 11:21:45

标签: jquery twitter-bootstrap jquery-validate

我想使用jquery验证程序插件检查切换按钮是否被按下。

$(document).ready(function() {
  $('form[id="my_form"]').validate({
    rules: {
      category_title: { required: true,},
      sort_order: {required: true,number: true,},
      options1: {required: true,},
    },
    submitHandler: function(form) {
        form.submit();
    }
  });
  $.validator.addMethod(
    "valueNotEquals",
    function(value, element, arg) {
        return arg !== value;
    },
    "Required."
  );
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/jquery.validation/1.16.0/jquery.validate.min.js"></script>

<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"></script>
<div class="form-group">
  <label class="tags">Status</label>
  <div class="btn-group btn-group-toggle" data-toggle="buttons">
    <label class="btn btn-secondary">
      <input type="radio" name="options1" id="option1" autocomplete="off" value="ON"> ON
    </label>
    <label class="btn btn-secondary">
      <input type="radio" name="options1" id="option2" autocomplete="off" value="OFF"> OFF
    </label>
  </div>
</div>

错误标签显示在按钮内部而不是按钮侧面,那么如何实现?

1 个答案:

答案 0 :(得分:1)

您可以使用引导程序切换

<link href="https://gitcdn.github.io/bootstrap-toggle/2.2.2/css/bootstrap-toggle.min.css" rel="stylesheet">
<script src="https://gitcdn.github.io/bootstrap-toggle/2.2.2/js/bootstrap-toggle.min.js"></script>


<label class="checkbox-inline">
  <input type="checkbox" checked data-toggle="toggle"> First
</label>

请在下面找到文档链接以进行更多自定义

http://www.bootstraptoggle.com/