开发者

How do you validate a field set with Jquery datepicker without disabling input

开发者 https://www.devze.com 2023-04-12 18:33 出处:网络
I can\'t disable the input, but I need to validate it no matter what the datepicker does. $(\"#datepicker\").datepicker({minDate: 0, maxDate: +7});

I can't disable the input, but I need to validate it no matter what the datepicker does.

$("#datepicker").datepicker({minDate: 0, maxDate: +7});

This produces the calendar I want, but won't validate the input field. 开发者_Go百科I have the validator plugin already in use requiring fields so I'd like to stick to that. This code will check if the field is required, but it won't check the max date:

$(document).ready(function() {

  $("#form").validate({
   rules: {
    datepicker: {
      required: true,
      date: true,
       maxDate: 7
          }
         }
       });
    });


See my jsfiddle, your js code should work.
Enter 10/22/2011 into the input field and press submit. The max date will be checked.

You can remove the maxDate row in your rules, it will be ignored.


As far as I know, "maxDate" is not a valid rule in vaildate plugin, so that's probably why it doesn't validate. Although, you can create custom rules using addMethod.

0

精彩评论

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

关注公众号