Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop jquery-ui datepicker from showing in beforeShow

I wish to do something like this:

var showme = false;

$('#mydatepicker').datepicker({
    beforeShow: function(input, inst) {
        if(!showme) {
            //stop showing
        }
    }
});

But disable, nor hide seems to work. I'd like to do something that works like preventDefault, but I don't think it'll work in this case.

like image 406
Alex KeySmith Avatar asked Dec 13 '22 11:12

Alex KeySmith


2 Answers

I had the same question, and have discovered that you can now use return false; to prevent the calendar from showing.

$('#mydatepicker').datepicker({
    beforeShow: function(input, inst) {
        if(!showme) {
            return false;
        }
    }
});

I'm using version 1.7.2 of jQuery UI

like image 180
Rachel Avatar answered Dec 30 '22 10:12

Rachel


Looking through the source, it doesn't look like that is possible currently. You might be able to request that as a feature. If you really want to make it stop (though this is probably a bad idea) you could throw an error in that function. Though this will cause errors to show up for your page and probably is not an option.


Note: I submitted a patch for this and it's now in the released jQuery UI (at least v1.9 and later), although the documentation doesn't mention it. return false in beforeShow will prevent the datepicker from appearing (now).

like image 26
joekarl Avatar answered Dec 30 '22 09:12

joekarl