I would like to bind to initialized datepicker "onSelect" function.
I've been trying hard to find a solution on the web, but was unsuccessful.
Anyone can tell me how to do it?
Do one of the following: For a text box control or a date picker control, ensure that the Data type list displays the appropriate data type, and then click Format. For an expression box control, ensure that the Format as list displays the appropriate data type, and then click Format.
You can simply use the setter
$('#datepicker').datepicker();
$('#datepicker').datepicker("option", "onSelect", function(){alert('hi')});
fiddle here http://jsfiddle.net/nhmsZ/
I found the above solutions caused problems in my case. Setting onSelect after the datepicker has already been initialised seems to cause the datepicker to be reinitialised. This may not be desirable.
If you are having problems it may be necessary to go through the back-door. This could have compatibility issues when JQUI is updated, but if you are willing to deal with that, then this code could help you out...
var inst = $.datepicker._getInst($('#startdate').get(0));
inst.settings.onSelect = function (dt) {
// your code here
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With