Question

Is there a way to fire a function if a validation failed using parsley?

I'm running into a situation where I have a few collapsed groups that I would like to open when there's a failure.

Basically, I want something like this:

$('#existingForm').parsley({
    onValidationFailureCallback: function() {
       openAllGroups();
    }
});

I couldn't find anything in the documentation that gives me this behavior.

Thanks!

Était-ce utile?

La solution

You can use the event parsley:field:error. When you listen to that event your callback will be triggered whenever there are errors present.

For example:

<form method="post" id="myForm">
    <input type="text" name="phone" value="" class="required" data-parsley-type="integer" />
    <input type="submit" value="Go">
</form>

$(document).ready(function() {
    $("#myForm").parsley();

    $.listen('parsley:field:error', function(){
        alert('there was an error');
        //openAllGroups(); // YOUR CODE HERE
    });
});

You can test it in the following fiddle http://jsfiddle.net/kuJPL/1/

Beware that this is only present since version 2.0.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top