[jQuery] Re: [validate] Same rule and messages to several input fields

2008-06-25 Thread Jörn Zaefferer
Great! I've added the example to the documentation here: http://docs.jquery.com/Plugins/Validation#Refactoring_rules

[jQuery] Re: [validate] Same rule and messages to several input fields

2008-06-25 Thread badtant
Thanks!! Worked great =) On Jun 24, 1:35 pm, "Jörn Zaefferer" <[EMAIL PROTECTED]> wrote: > How about this: > > $.validator.addMethod("customerRequired", > $.validator.methods.required, "Fyll i"); > $.validator.addMethod("customerMinlength", function(value, element) { >   return $.validator.method

[jQuery] Re: [validate] Same rule and messages to several input fields

2008-06-24 Thread Jörn Zaefferer
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 ad

[jQuery] Re: [validate] Same rule and messages to several input fields

2008-06-24 Thread badtant
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 i

[jQuery] Re: [validate] Same rule and messages to several input fields

2008-06-23 Thread Jörn Zaefferer
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 en

[jQuery] Re: [validate] Same rule and messages to several input fields

2008-06-23 Thread badtant
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 w

[jQuery] Re: [validate] Same rule and messages to several input fields

2008-06-23 Thread Jörn Zaefferer
One option would to use addClassRules (http://docs.jquery.com/Plugins/Validation/Validator/addClassRules#namerules) 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