Display loading gif after parsley.js validates for

2019-09-18 06:27发布

Have a an upload form with some required fields which uses parsley.js to validate. I want to display a loading gif after the form has been validated and the actual uploading starts.

I've tried using an onsubmit event to call a function which changes the visibility of the loading gif from hidden to visible. But the gif shows up when ever the upload button is clicked even if the form has not been validated.

Thanks in advance!

1条回答
爷、活的狠高调
2楼-- · 2019-09-18 06:31

You'll have to use Parsley events (http://parsleyjs.org/doc/index.html#psly-events-list) and do something like that:

$('#form').parsley().subscribe('parsley:form:validated', function (parsleyForm) {
  if (true === parsleyForm.validationResult )
     // display gif
  else
     // do something else, or nothing
});

Best

查看更多
登录 后发表回答