JQuery Date Override Function

I created some custom dumper using jQuery datepicker and it works fine. There are some scenarios when I need some functionality for the onSelect event and you want to override it. But I do not need to change any other setting from the initial datepicker.

here is my sample code:

$('#start_date.datepicker, #end_date.datepicker').attachCustomDatepicker(); $('#start_date.datepicker').datepicker({ onSelect: function(dateValue, inst) { $('#end_date.datepicker').datepicker("option", "minDate", dateValue); } }); 
+2
jquery jquery-ui datepicker
04 Oct
source share
1 answer

Since this is not possible, I am thinking of a workaround: pass the function as a parameter to the jQuery user-defined function. This is the code for creating datepickers:

 var onSelectFunction = function(dateValue){ $('#end_date.datepicker').datepicker("option", "minDate", dateValue); } options.onSelect = onSelectFunction; $('#start_date.datepicker, #end_date.datepicker').attachCustomDatepicker(options); 

and this is a preview of my custom function:

 $.fn.attachCustomDatepicker = function(options) { var defaultOptions = { someDefaultCustomParamsHere: , onSelect: null } var onSelectFunction = function(params){ return false; } if (typeof options == 'object') { options = $.extend(defaultOptions, options); } else { options = defaultOptions; } if(!options.onSelect){ options.onSelect = onSelectFunction; } $(this).datepicker( "destroy" ); $(this).datepicker({ onSelect: function (dateValue, inst) { options.onSelect(dateValue); } } } 
+1
Oct 08 '12 at 2:00
source share



All Articles