[jQuery] Re: using depends method with Validate() plugin

2008-12-03 Thread luke adamis


Is there a reason for this to not work?

other_product_interest: {
required: #product_interest[0]:checked
},

product_interest[] is a list of checkboxes, if user picks 'other' ,  
#product_interest[0] then user must fill the text filed:  
other_product_interest.


Thanks,
Luke



[jQuery] Re: using depends method with Validate() plugin

2008-12-03 Thread Jörn Zaefferer
I guess you have to escape that ID: jQuery interprets that as element
with id product_interest and an attribute named '0'.

Jörn

On Wed, Dec 3, 2008 at 5:24 PM, luke adamis [EMAIL PROTECTED] wrote:

 Is there a reason for this to not work?

other_product_interest: {
required:
 #product_interest[0]:checked
},

 product_interest[] is a list of checkboxes, if user picks 'other' ,
 #product_interest[0] then user must fill the text filed:
 other_product_interest.

 Thanks,
 Luke




[jQuery] Re: using depends method with Validate() plugin

2008-12-03 Thread luke adamis


Thanks,
That did it.
Now I have another issue:

these checkboxes must be names like an array:

product_interest[]

but in the rules I can't have this:

product_interest[]: required,

I know I can insert code in HTML:
class=required

but I would rather have it in the rules.

Is there any way to do that?

L.


On Dec 3, 2008, at 11:30 AM, Jörn Zaefferer wrote:


I guess you have to escape that ID: jQuery interprets that as element
with id product_interest and an attribute named '0'.

Jörn

On Wed, Dec 3, 2008 at 5:24 PM, luke adamis [EMAIL PROTECTED]  
wrote:


Is there a reason for this to not work?

   other_product_interest: {
   required:
#product_interest[0]:checked
   },

product_interest[] is a list of checkboxes, if user picks 'other' ,
#product_interest[0] then user must fill the text filed:
other_product_interest.

Thanks,
Luke







[jQuery] Re: using depends method with Validate() plugin

2008-12-03 Thread Jörn Zaefferer
See 
http://docs.jquery.com/Plugins/Validation/Reference#Fields_with_complex_names_.28brackets.2C_dots.29

Jörn

On Wed, Dec 3, 2008 at 6:58 PM, luke adamis [EMAIL PROTECTED] wrote:

 Thanks,
 That did it.
 Now I have another issue:

 these checkboxes must be names like an array:

 product_interest[]

 but in the rules I can't have this:

product_interest[]: required,

 I know I can insert code in HTML:
 class=required

 but I would rather have it in the rules.

 Is there any way to do that?

 L.


 On Dec 3, 2008, at 11:30 AM, Jörn Zaefferer wrote:

 I guess you have to escape that ID: jQuery interprets that as element
 with id product_interest and an attribute named '0'.

 Jörn

 On Wed, Dec 3, 2008 at 5:24 PM, luke adamis [EMAIL PROTECTED] wrote:

 Is there a reason for this to not work?

   other_product_interest: {
   required:
 #product_interest[0]:checked
   },

 product_interest[] is a list of checkboxes, if user picks 'other' ,
 #product_interest[0] then user must fill the text filed:
 other_product_interest.

 Thanks,
 Luke







[jQuery] Re: using depends method with Validate() plugin

2008-12-02 Thread luke adamis


OK

this works:

current_password: {
minlength: 6,
required: {
depends: #new_password:filled
  }
},


I still need to figure out how to get a value recognized:

zip: {
required: {
depends: #countrycode:'1'
  }
 },

Luke


On Dec 2, 2008, at 11:44 AM, luke adamis wrote:



Hi,

I am using the Validate() plugin for various forms and I run into
this issue with the depends method on various places.

So far I found only two references to dealing with depends:

http://docs.jquery.com/Plugins/Validation/validate

$(.selector).validate({
rules: {
  contact: {
required: true,
email: {
  depends: function(element) {
return $(#contactform_email:checked)
  }
}
  }
}
})

http://dev.jquery.com/ticket/2456

billingAddress: {
   required:true,
   minlength:5
   equalTo: {
 param: #shippingaddress,
 depends: #compare:checked
   }
}

first of all non of these work for me so there must be something
going on with them. but my real problem is that I want validation
depending on fields other then checkboxes.

1. I only want to require zip code if the selected country from a
drop down list is USA.

something like this:

zip: {
required: {
depends: #countrycode:1
}
},

where countrycode represents the country selector and 1 is the value
for USA

2. in a from for password change I only want to require current
password if new password is entered.
something like this:

current_password: {
minlength: 6,
required: {
depends: #new_password
}
},

with this one I'd assume that if new_password is not empty then set
the rule.

I also found this page:
http://dev.distilldesign.com/log/2008/mar/16/extending-jquery-form-
validation-plugin/
http://lab.distilldesign.com/jquery-form-validation/extending/

this one works, though he uses checkboxes as well. here he basically
extends the validate() plugin:

$.validator.addMethod('dependsOn', function (value, el, params) {
return !$(params.el).is(params.being) || 
$(el).is(':filled');
}, 'This field is required.');

then he uses the new method in the rule:

emailDependent: {
dependsOn: {
el: '#emailMethod',
being: ':checked'
},
email: true
},


I am not a javascript wizard so this method writing is getting my
head dizzy. Can anyone tell me if there is a simple way of using
depends in rules for validate() plugin?

Thanks,
Luke







[jQuery] Re: using depends method with Validate() plugin

2008-12-02 Thread Jörn Zaefferer
Either depends: #countrycode[value=1] or depends: function() {
return $(#countrycode).val() == '1'; }

Jörn

On Tue, Dec 2, 2008 at 8:42 PM, luke adamis [EMAIL PROTECTED] wrote:

 OK

 this works:

current_password: {
minlength: 6,
required: {
depends:
 #new_password:filled
  }
},


 I still need to figure out how to get a value recognized:

zip: {
required: {
depends: #countrycode:'1'
  }
 },

 Luke


 On Dec 2, 2008, at 11:44 AM, luke adamis wrote:


 Hi,

 I am using the Validate() plugin for various forms and I run into
 this issue with the depends method on various places.

 So far I found only two references to dealing with depends:

 http://docs.jquery.com/Plugins/Validation/validate

 $(.selector).validate({
rules: {
  contact: {
required: true,
email: {
  depends: function(element) {
return $(#contactform_email:checked)
  }
}
  }
}
 })

 http://dev.jquery.com/ticket/2456

 billingAddress: {
   required:true,
   minlength:5
   equalTo: {
 param: #shippingaddress,
 depends: #compare:checked
   }
 }

 first of all non of these work for me so there must be something
 going on with them. but my real problem is that I want validation
 depending on fields other then checkboxes.

 1. I only want to require zip code if the selected country from a
 drop down list is USA.

 something like this:

 zip: {
required: {
depends: #countrycode:1
}
},

 where countrycode represents the country selector and 1 is the value
 for USA

 2. in a from for password change I only want to require current
 password if new password is entered.
 something like this:

 current_password: {
minlength: 6,
required: {
depends: #new_password
}
},

 with this one I'd assume that if new_password is not empty then set
 the rule.

 I also found this page:
 http://dev.distilldesign.com/log/2008/mar/16/extending-jquery-form-
 validation-plugin/
 http://lab.distilldesign.com/jquery-form-validation/extending/

 this one works, though he uses checkboxes as well. here he basically
 extends the validate() plugin:

 $.validator.addMethod('dependsOn', function (value, el, params) {
return !$(params.el).is(params.being) ||
 $(el).is(':filled');
}, 'This field is required.');

 then he uses the new method in the rule:

 emailDependent: {
dependsOn: {
el: '#emailMethod',
being: ':checked'
},
email: true
 },


 I am not a javascript wizard so this method writing is getting my
 head dizzy. Can anyone tell me if there is a simple way of using
 depends in rules for validate() plugin?

 Thanks,
 Luke







[jQuery] Re: using depends method with Validate() plugin

2008-12-02 Thread luke adamis


Thanks!

I found the page as well:
http://docs.jquery.com/Plugins/Validation/Methods/required#dependency- 
expression


I wonder how I could miss this page.

Luke

On Dec 2, 2008, at 2:05 PM, Jörn Zaefferer wrote:


Either depends: #countrycode[value=1] or depends: function() {
return $(#countrycode).val() == '1'; }

Jörn

On Tue, Dec 2, 2008 at 8:42 PM, luke adamis [EMAIL PROTECTED]  
wrote:


OK

this works:

   current_password: {
   minlength: 6,
   required: {
   depends:
#new_password:filled
 }
   },


I still need to figure out how to get a value recognized:

   zip: {
   required: {
   depends:  
#countrycode:'1'

 }
},

Luke


On Dec 2, 2008, at 11:44 AM, luke adamis wrote:



Hi,

I am using the Validate() plugin for various forms and I run into
this issue with the depends method on various places.

So far I found only two references to dealing with depends:

http://docs.jquery.com/Plugins/Validation/validate

$(.selector).validate({
   rules: {
 contact: {
   required: true,
   email: {
 depends: function(element) {
   return $(#contactform_email:checked)
 }
   }
 }
   }
})

http://dev.jquery.com/ticket/2456

billingAddress: {
  required:true,
  minlength:5
  equalTo: {
param: #shippingaddress,
depends: #compare:checked
  }
}

first of all non of these work for me so there must be something
going on with them. but my real problem is that I want validation
depending on fields other then checkboxes.

1. I only want to require zip code if the selected country from a
drop down list is USA.

something like this:

zip: {
   required: {
   depends: #countrycode:1
   }
   },

where countrycode represents the country selector and 1 is the value
for USA

2. in a from for password change I only want to require current
password if new password is entered.
something like this:

current_password: {
   minlength: 6,
   required: {
   depends: #new_password
   }
   },

with this one I'd assume that if new_password is not empty then set
the rule.

I also found this page:
http://dev.distilldesign.com/log/2008/mar/16/extending-jquery-form-
validation-plugin/
http://lab.distilldesign.com/jquery-form-validation/extending/

this one works, though he uses checkboxes as well. here he basically
extends the validate() plugin:

$.validator.addMethod('dependsOn', function (value, el, params) {
   return !$(params.el).is 
(params.being) ||

$(el).is(':filled');
   }, 'This field is required.');

then he uses the new method in the rule:

emailDependent: {
   dependsOn: {
   el: '#emailMethod',
   being: ':checked'
   },
   email: true
},


I am not a javascript wizard so this method writing is getting my
head dizzy. Can anyone tell me if there is a simple way of using
depends in rules for validate() plugin?

Thanks,
Luke