I'm using parsley js in two forms in a single page. i want to trigger parsley validator when i click on a type='button' field and validate the first form to check only 3 fields of the form. Initially there are around 7 fields in the form included for validation. So far I couldn't make it work. tried this but no luck.
any idea?
update: this is my code;
<div class = 'two'>
<input type='text' id='firstname' name='firstname' />
</div>
$('#form').parsley({
excluded: '.two input'
});
$('#form').parsley('validate');
i just tried to exclude one field and test if the form is validating as i want it to be. But still it validates input field inside css class 'two'. that's all i have done so far. no clue..
You have a couple of issues with your code, specifically with this line:
that should be
That is, you have
dir
instead ofdiv
andclasss
instead ofclass
. You should also use$('#form').parsley().validate()
instead of$('#form').parsley('validate')
.The following code will work:
You can view a more complete working example in this jsfiddle
For your case, you should consider using
data-parsley-group
(see the docs) to achieve the same result, with the following code:The difference between the two, is that in the first example you redefine the
excluded
option. In the second example you would usedata-parsley-group
and validate only that group.For a complete example, visit this jsfiddle (you can test it and change
$('#form').parsley().validate("second");
to$('#form').parsley().validate("first");
to see what happens).just an add on to the answer above, to work correctly , use group name in isValid too,ie $('#form').parsley().isValid("second")).