I would love to have this feature.  It would save me a bunch of extra
lines of code.  Any idea if and when this might be implemented into
the plugin?

On Oct 21, 5:55 am, lightglitch <[EMAIL PROTECTED]> wrote:
> Done.
>
> http://dev.jquery.com/ticket/3503
>
> On Oct 21, 9:53 am, "Jörn Zaefferer" <[EMAIL PROTECTED]>
> wrote:
>
> > Could you file a ticket for this?http://dev.jquery.com/newticket
> > (requires registration)
>
> > Thanks!
>
> > Jörn
>
> > On Mon, Oct 20, 2008 at 8:49 PM, lightglitch <[EMAIL PROTECTED]> wrote:
>
> > > I have made a patch for my app to therulesfunction to supportcustom
> > > messages:
>
> > > This is the new function, would be nice to have something similar to
> > > this.
>
> > >        rules: function(command, argument) {
> > >                var element = this[0];
>
> > >                if (command) {
> > >                        var staticRules = $.data(element.form, 
> > > 'validator').settings.rules;
> > >                        var existingRules = 
> > > $.validator.staticRules(element);
> > >                        switch(command) {
> > >                        case "add":
> > >                                $.extend(existingRules, 
> > > $.validator.normalizeRule(argument));
> > >                                staticRules[element.name] = existingRules;
>
> > >                                /**** PATCH ***/
> > >                                if (argument.messages) {
> > >                                    if ($.data(element.form,
> > > 'validator').settings.messages[element.name])
> > >                                         $.extend($.data(element.form,
> > > 'validator').settings.messages[element.name],argument.messages);
> > >                                   else
> > >                                        $.data(element.form,
> > > 'validator').settings.messages[element.name] = argument.messages;
> > >                                }
> > >                                /**** END PATCH ***/
> > >                                break;
> > >                        case "remove":
> > >                                if (!argument) {
> > >                                        delete staticRules[element.name];
> > >                                        return existingRules;
> > >                                }
> > >                                var filtered = {};
> > >                                $.each(argument.split(/\s/), 
> > > function(index, method) {
> > >                                        filtered[method] = 
> > > existingRules[method];
> > >                                        delete existingRules[method];
> > >                                });
> > >                                return filtered;
> > >                        }
> > >                }
>
> > >                var data = $.validator.normalizeRules(
> > >                $.extend(
> > >                        {},
> > >                        $.validator.metadataRules(element),
> > >                        $.validator.classRules(element),
> > >                        $.validator.attributeRules(element),
> > >                        $.validator.staticRules(element)
> > >                ), element);
>
> > >                // make sure required is at front
> > >                if (data.required) {
> > >                        var param = data.required;
> > >                        delete data.required;
> > >                        data = $.extend({required: param}, data);
> > >                }
>
> > >                return data;
> > >        },
>
> > > And I use it like this:
>
> > > $("#field").rules("add",  {"required":true,"range":[5,45],"messages":
> > > {"required":"The field can\'t be blank.","range":"The field must have
> > > 5 to 45 characters."}});
>
> > > Hope it helps.
>
> > > On Oct 9, 11:00 pm, "Jörn Zaefferer" <[EMAIL PROTECTED]>
> > > wrote:
> > >> You can use metadata, too. Currently barely documented, and not really
> > >> recommended either, but works since 1.4.
>
> > >> <input class="{required:true,messages:{required:'required field'}}"
> > >> name="whatever" />
>
> > >> Jörn
>
> > >> On Thu, Oct 9, 2008 at 5:20 PM, Bob Silverberg <[EMAIL PROTECTED]> wrote:
>
> > >> > Thanks for the quick response.  That fixed my problem.
>
> > >> > One more question:
>
> > >> > I'd like to addcustomerror messages to some of my dynamic
> > >> > validations.  Is it correct that the only way to add acustomerror
> > >> >messageto a particular rule is either by:
>
> > >> > 1. using the form.validate() method
> > >> > 2. using $.validator.addMethod to clone an existing method
>
> > >> > Thanks,
> > >> > Bob
>
> > >> > On Thu, Oct 9, 2008 at 4:22 AM, Jörn Zaefferer
> > >> > <[EMAIL PROTECTED]> wrote:
> > >> >> Forrules("add") to work, the element's form has to be validated, that
> > >> >> is, call $("form").validate() first. I've updated the documentation
> > >> >> accordingly.
>
> > >> >> Not sure why the attr-approach failed, I'll take a look at that.
>
> > >> >> Jörn
>
> > >> >> On Thu, Oct 9, 2008 at 2:37 AM, BobS <[EMAIL PROTECTED]> wrote:
>
> > >> >>> I'm working on a server-side component that will generate all of my
> > >> >>> jQuery validationrulesfrom xml metadata, so I'm trying to
> > >> >>> dynamically addrulesone at a time.
>
> > >> >>> My first attempt was to use therules( "add",rules) syntax, but I'm
> > >> >>> getting an error on page load:
>
> > >> >>> jQuery.data(element.form, "validator") is undefined
>
> > >> >>> Here's the syntax I'm using:
>
> > >> >>> $("#VerifyPassword").rules('add',{equalTo: '#UserPass'});  which 
> > >> >>> seems
> > >> >>> to be correct according to the docs.
>
> > >> >>> So, I decided to try setting attributes instead, which works fine for
> > >> >>> the equalTo. For example, this works:
>
> > >> >>> $("#VerifyPassword").attr('equalTo','#UserPass');
>
> > >> >>> But when trying to use attr to set a range I cannot figure out what 
> > >> >>> to
> > >> >>> pass in for the range.
>
> > >> >>> I've tried:
> > >> >>> $("#UserPass").attr('rangelength','[5,10]'); -> yeilds themessage
> > >> >>> "Please enter a value between NaN and 5 characters long."
> > >> >>> $("#UserPass").attr('rangelength',[5,10]);  -->  yields themessage
> > >> >>> "Please enter a value between 5 and NaN characters long."
> > >> >>> var theRange = [5,10]; $("#UserPass").attr('rangelength',theRange);  
> > >> >>> --
> > >> >>>>  yields themessage"Please enter a value between 5 and NaN
> > >> >>> characters long."
>
> > >> >>> So, I really have 2 questions:
>
> > >> >>> 1. How can I a rule using therules( "add",rules) syntax, which
> > >> >>> would be my preferred approach?
> > >> >>> 2. If I need to add a validation using attr, what format do I use to
> > >> >>> pass in the value of the rangelength attribute?
>
> > >> >>> Thanks in advance for any help anyone can provide,
> > >> >>> Bob
>
> > >> > --
> > >> > Bob Silverberg
> > >> >www.silverwareconsulting.com

Reply via email to