Reputation: 25161
Im trying to append or add a function to the existing call stack for jqueryui's datepicker 'onSelect' event, but am failing miserably.
Ive pasted an example of what im trying to do here.
Basically, it should alert('abc')
, then alert('def')
after the first datepicker selection has been made.
Any advice appreciated.
Upvotes: 1
Views: 1946
Reputation: 26838
After you called this
$('#hello').datepicker("option", "onSelect", function(){
var prevFunction ...
the current event handler is already the new one! So when the event fires and the following code executes
var prevFunction = $(this).datepicker("option","onSelect");
prevFunction
points to itself. You can solve this using an IIFE:
$('#hello').datepicker("option", "onSelect",
(function() {
var prevFunction = $('#hello').datepicker("option","onSelect");
return function(){
prevFunction();
alert('def');
};
}()));
Now var prevFunction = ..
is called immediately and the old handler is stored. The new handler is assigned with return function(){ ...
.
Upvotes: 2