How about this: $.validator.addMethod("customerRequired", $.validator.methods.required, "Fyll i"); $.validator.addMethod("customerMinlength", function(value, element) { return $.validator.methods.minlength.call(this, value, element, 2); }, "Förnamnet måste vara minst 2 tecken");
Then either add those two classes to all customer fields: <input name="customer1" class="customerRequired customerMinlength" /> Or create a compound for that: $.validator.addClassRules("customer", { customerRequired: true, customerMinlength: true }); <input name="customer1" class="customer" /> Using the latter, you could simplify the custom method for minlength, resulting in this: $.validator.addMethod("customerRequired", $.validator.methods.required, "Fyll i"); $.validator.addMethod("customerMinlength", $.validator.methods.minlength, "Förnamnet måste vara minst 2 tecken"); $.validator.addClassRules("customer", { customerRequired: true, customerMinlength: 2 }); Jörn On Tue, Jun 24, 2008 at 10:01 AM, badtant <[EMAIL PROTECTED]> wrote: > > Hmm, I don't quite understand how to implement this. > > Let's say that i have this now: > > rules: > customer:{ > required:true, > minlength:2 > } > > messages: > customer:{ > required:"Fyll i", > minlength:"Förnamnet måste vara minst 2 tecken" > } > > How do i convert this to the addMethod functionality, and how to i use > it once it's done? > > I also just read the changelog: > http://dev.jquery.com/view/trunk/plugins/validate/changelog.txt > Is #2908 the functionality that I'm requesting? If so, when will 1.4 > be released =) > > /Niklas > > On Jun 23, 5:46 pm, "Jörn Zaefferer" <[EMAIL PROTECTED]> > wrote: >> You could add a custom method that uses the required-implementation, >> but provides a different default message: >> >> jQuery.validator.addMethod("customer", >> jQuery.validator.methods.required, "Välj om du är kund hos Avanza >> eller ej"); >> >> Please let me know if that works for you, the idea is interesting >> enough to add it to the >> addMethod-documentation:http://docs.jquery.com/Plugins/Validation/Validator/addMethod >> >> Jörn >> >> On Mon, Jun 23, 2008 at 3:41 PM, badtant <[EMAIL PROTECTED]> wrote: >> >> > Ahh, that could be something. But what about the messages? >> > I can have an unknow number of customer fields in my form and I can't >> > add lets say a hundred messages that looks exactly the same just to be >> > sure. >> > Something similair to addClassRules (addClassMessages?) would be >> > awsome. Is there no other way around it? >> >> > /Niklas >> >> > On Jun 23, 3:16 pm, "Jörn Zaefferer" <[EMAIL PROTECTED]> >> > wrote: >> >> One option would to use addClassRules >> >> (http://docs.jquery.com/Plugins/Validation/Validator/addClassRules#nam...) >> >> to create a composite rule, then apply that class to all customer >> >> fields. You'd still need to provide the messages - you could set it as >> >> the default via $.validator.messages.required = "...". >> >> >> Jörn >> >> >> On Mon, Jun 23, 2008 at 2:23 PM, badtant <[EMAIL PROTECTED]> wrote: >> >> >> > Hi, >> >> >> > This post concerns the Validation plugin >> >> >http://bassistance.de/jquery-plugins/jquery-plugin-validation/ >> >> >> > I have several input fields that should have the same rules and >> >> > messages. I don't want to specify them over and over again so my >> >> > question is: how can I do that? >> >> >> > Here's an example: >> >> >> > rules:{ >> >> > customer1:{ >> >> > required:true >> >> > } >> >> > }, >> >> > messages:{ >> >> > customer1:{ >> >> > required:"Välj om du är kund hos Avanza >> >> > eller ej" >> >> > } >> >> > } >> >> >> > Now I wan't the same to apply to the names customer2, customer3, >> >> > customer4 and so in. >> >> >> > Thanks! >> >> > /Niklas >