JQueryUI datepicker widget adds onClose function after widget initialization

Say I have a #date field. First, I initialize it with some options (at the moment they are not important):

$('#date').datepicker(options); 

Then, if I try to add the onClose function, I would do:

 $('#date').datepicker({onClose: function(dateText, inst){console.log("Hello World");}}); 

Howerver, this overrides the parameters set previously. Let's say I do not have access to these parameters - the datepicker is initialized, the parameters are set, and now I need to add the onClose function. How to do it? I tried .datepicker('option','onClose',function(){}); no effect.

+6
source share
5 answers

Try to do it like

 $('#date').datepicker( 'option' , 'onClose', function() {} ); 
+6
source

Try the following:

 $('#date').datepicker(); ... $('#date').datepicker("option", { onClose: function(dateText, inst){console.log("Hello World");} }); 

Of course, this will override the previous onClose function that you specified earlier. source: jQuery forum post

+5
source

Try the following:

 $('#date').datepicker().bind('onClose',function(){ console.log("Hello World"); }); 
0
source

Define the on-close function as just one of your options in initialization. This works for me.

 $('#date').datepicker({ dateFormat: "dd/mm/yy", onClose: function(dateText, inst){console.log("Hello World");} }); 
0
source

I also had a problem with older functions being closed. After a lot of searching, and I am implementing my own function to solve this problem. Below is a snippet of code

 function addCloseFunctionToDatePicker(id, funHandler) { var $datePicker=$('#' + id); var prevhandler = $datePicker.datepicker('option', 'onClose'); $datePicker.datepicker('option', { onClose: function (dateText, inst) { if (prevhandler) { prevhandler(dateText, inst); } funHandler(dateText, inst); } }); } 

Call mechanism:

  addCloseFunctionToDatePicker('myDatePicker', function(){ alert("I'm next method"); }); 
0
source

All Articles