Parsley.js 1.x - Error when form data attributes are changed on the fly

旧巷老猫 提交于 2019-12-04 18:28:48

Parsley is based on data attributes, that are binded by jQuery with .data()

Unfortunately, when you add a data- attr, it is not binded to jQuery .data(). You'll have to add the validators this way on the fly:

<script>
// wait for the DOM to be loaded 
    $(document).ready(function() {
      // destroy
      $('#myForm').parsley('destroy');
      // change attribute
      $('#myTestField').data('minlength', 2);
      // assign parsley to do the job
      $('#myForm').parsley();
    });
</script>

I'll add an API to add / edit / remove validators on the fly, without having to call destroy :)

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