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 add custom error messages to some of my dynamic
> validations.  Is it correct that the only way to add a custom error
> message to 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:
>> For rules("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 validation rules from xml metadata, so I'm trying to
>>> dynamically add rules one at a time.
>>>
>>> My first attempt was to use the rules( "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 the message
>>> "Please enter a value between NaN and 5 characters long."
>>> $("#UserPass").attr('rangelength',[5,10]);  -->  yields the message
>>> "Please enter a value between 5 and NaN characters long."
>>> var theRange = [5,10]; $("#UserPass").attr('rangelength',theRange);  --
>>>>  yields the message "Please enter a value between 5 and NaN
>>> characters long."
>>>
>>> So, I really have 2 questions:
>>>
>>> 1. How can I a rule using the rules( "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