.submit() is always executed even when Parsley validation fails

旧巷老猫 提交于 2019-12-11 15:16:01

问题


I'm using parsley.js for validation. It does the job without using Ajax. But when I add a .submit() function, its always fired and does not wait for validation.

UPDATE: I need to use remote validation too

$(document).ready(function(){

  $('#form_register').submit(function(){
    alert('The form submitted');
  })

});

https://jsfiddle.net/rostamiani/mzdvLpnt/3/

It works in fiddler but not in my page. The I attached my page: https://ufile.io/hm7w5


回答1:


UPDATE This code does not work for remote validation. When remote validation is used, isValid returns null!

I used isValid() function to check validation status at submit.

$('#form_register').submit(function(e){

    // Prevent normal submittion
    e.preventDefault();

    // If the form is not submitted yet, skip
    if (! $('#form_register').parsley().isValid()) {
        return;
    }

    alert('The form submitted');
}


来源:https://stackoverflow.com/questions/51345227/submit-is-always-executed-even-when-parsley-validation-fails

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