Search code examples
javascriptjqueryjquery-uijquery-ui-datepickerpreventdefault

Open datepicker on condition


I want my datepicker to open only under condition, in this case the presence of a class, here's the not working code:

$('.ui-datepicker-trigger').click(function(e){
    if ($(this).hasClass('disableDatepicker')) {
        e.preventDefault();
    }
});

Thanks!


Solution

  • This should be work

    $("input").datepicker({ 
             beforeShow: function(a,b){ 
                 if ($(this).hasClass('disableDatepicker')) return false;  
             } 
    });
    

    http://jsfiddle.net/scTwm/2/