简体   繁体   中英

Parsley.js validation

As an exercise I have added some parsley validation to this form here http://matthewpiatetsky.com/cs401/login.html

I am now trying to add a similar validation to the form here http://matthewpiatetsky.com/cs401/writereviews.html
(I have some mouseout validation on the text area)

I am running into two issues:

  1. How can I get the form to validate before the form submits to its action? Can I run validation first, and if validation succeeds, then submit the form.
  2. How can I add data-required="true" to the jquery raty stars to force the user to fill those in?

Thanks!

For validation before submit you can do something like:

var form = document.getElementById(“yourFormID”);

form.addEventListener("submit", function(event) {
    // do your additional validation here

    if (something wrong)
        event.preventDefault();

}, false);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM