LemonMan
LemonMan

Reputation: 3153

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!

Upvotes: 0

Views: 640

Answers (1)

Anto Jurković
Anto Jurković

Reputation: 11258

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);

Upvotes: 1

Related Questions