开发者

jquery validate - valid if hidden field has a value

开发者 https://www.devze.com 2023-04-05 05:38 出处:网络
I need to validate a field based on the value of a hidden field. I tried this custom rule: jQuery.validator.addMethod(\"cityselected\", function() {

I need to validate a field based on the value of a hidden field. I tried this custom rule:

jQuery.validator.addMethod("cityselected", function() {
    if ($('#featureID').val() == "") return false;
    else return true;
});

cityselect: {
    required: true,
    cityselected: t开发者_如何学编程rue
},

featureID is a hidden input which I need to check has a value. This doesnt seem to work though. Any ideas?


Add the class "required" to the hidden input.


If your plugin version is greater than 1.9, you'll have to explicitly add hidden to the validation process, like that when you initialize the plugin :

$("#form").validate({
  // Do not ignore hidden fields
  ignore: []
});
0

精彩评论

暂无评论...
验证码 换一张
取 消