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