bauhausweb
bauhausweb

Reputation: 137

ParsleyJS - Validate multiple fields

I'm trying to validate multiple fields at once, but e.g. $('select[name="country"], input[name="prefix"]').parsley().validate(); is not working.

To be precise, the select seems to be the issue as I can validate $('input[name="prefix"]').parsley().validate(); but $('select[name="country"]').parsley().validate(); is not working :(

What could be the reason? Thanks for your input, I'm still learning...

Upvotes: 0

Views: 898

Answers (1)

leo.fcx
leo.fcx

Reputation: 6467

Apparently parsley does not work on a set of elements, in that case validation is only applied to first element from the set.

An alternative to work-around your problem would be to loop the set of elements as follows:

$('input:first, input:last, select').each(function(index, el){
  $(el).parsley().validate();
});

See working JSFiddle here.

Upvotes: 1

Related Questions