Configure Parsley using Javascript, not html data attributes

后端 未结 1 1775
臣服心动
臣服心动 2021-01-20 08:38

How do I configure Parsley using javascript, not html data attributes?

The documentation examples show how to configure the Parsley form instance and some global fie

相关标签:
1条回答
  • 2021-01-20 08:59

    @kim-prince Hope this helps

    <form id="myForm">
      <input id="number" placeholder="Number" />
      <input type="submit" />
    </form>
    
    <script>
    $('#myForm').parsley();
    $("#number").parsley().addConstraint('type','number');
    $("#number").parsley().addConstraint('minlength',2);
    $("#number").parsley().addConstraint('required');
    </script>

    see working codepen: http://codepen.io/ds0001/pen/QwoRVx?editors=101

    0 讨论(0)
提交回复
热议问题