jQueryValidate - Required field - depends doesn't work
Your syntax and use of the plugin is correct from what you have given. You need to troubleshoot, so first try this
marque: {
required: true;
}
simple. Does the error message appear? If yes then try this
marque: {
required: {
depends: function () { return true; /* or false */ }
}
}
You really should be able to do this without the depends
option, just make the function work directly on the required
object:
rules: {
marque: {
required: function() {
if (($('#add_marque').val() == "Ajouter une marque" && (('#marque').val() == -1) || ($('#add_marque').val() == "" && $('#marque').val() == -1)) {
return true;
}
else {
return false;
}
}
}
}
See a working, simpler example here: http://jsfiddle.net/ryleyb/3hqH6/1/