开发者

JQuery UI Datepicker - constricting input on the text field in regard to the minDate option?

$('#Date_Of_Reservation').datepicker({showAnim: 'fadeIn',minDate: twoBussinessDaysToDays(),constrainInput: true});

My function works 开发者_C百科fine. The graphical calendar works fine as well - graying out the non-selectable dates. The problem is the validation. While the minDate field is working if the user types the date in manually into the text field they can enter dates prior to the minDate. No validation in regard to the minDate occurs. Is there an elegant solution for this problem?

Edit: It does work great when I push enter after putting something in the text field. But when I tab or click somewhere else the validation isn't triggered.


  1. Use the validator plugin to ensure valid input
  2. Add a custom date range method

the method in your case would be:

$.validator.addMethod("dateRange", function(value, element) {
    // put your own logic here something like this
    return new Date(value) > twoBussinessDaysToDays();
},
"Please enter a valid date"
);

And tell jquery to validate the form:

$('#myForm').validate({
    rules: {
        Date_Of_Reservation: { dateRange: true }
    }
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜