Configure Parsley using Javascript, not html data attributes

匆匆过客 提交于 2019-12-20 01:45:44

问题


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 field options using JS, but I want to be able to add and configure all field instances that way too. I don't want to use the html data attributes. Is that possible?

I think this question is driving at the same problem, How to use ParsleyJS 2.* using javascript and not data attributes, but it's not 100% clear.


回答1:


@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



来源:https://stackoverflow.com/questions/29246268/configure-parsley-using-javascript-not-html-data-attributes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!