Just define classHandler function before Parsley library import, in my case, i'm using bootstrap and it's to apply error and valid classes on parent div (it has "form-group" class).
<script>
window.ParsleyConfig = {
classHandler: function ( parsleyField) {
// specify where parsley error-success classes will be set
return parsleyField.$element.parent();
// Change this to change the element to apply too
},
};
</script>
Now just add data-parsley validate to your form tag :
<form method="post" id="form1" data-parsley-validate>
When using bootstrap, you need to specify bootstrap error and valid classes too
<form method="post" id="form1" data-parsley-error-class="has-error" data-parsley-success-class="has-success" data-parsley-validate>
In order to get the "has-error" class set on the parent div on invalid/error state (same for valid too):
<div class="form-group has-error">
<label>Name</label>
<input class="form-control" type="text" id="name" name="name" required="" data-parsley-trigger="keyup" data-parsley-minlength="5">
<p class="help-block">Example help text here.</p>
</div>
This solution global to all fields.