Opened 11 years ago

Last modified 9 years ago

#8066 open feature

datepicker setDate should trigger onSelect

Reported by: sprugman Owned by:
Priority: minor Milestone: none
Component: ui.datepicker Version: 1.8.17
Keywords: Cc:
Blocked by: Blocking:


If I have an event handler onSelect, I want it to fire when I change the selection via setDate. Here's a fiddle that demonstrates it not happening.

Change History (9)

comment:1 Changed 11 years ago by enbergj

This is actually quite important, since there seems to be no SANE way to programmatically trigger the onSelect callback.

For example in my case, I'm using a Yii widget that wraps around jQuery UI datepicker, listens for the onSelect and updates the selected date in an input field to be submitted. I then use the setDate callback from JavaScript to update the selected date on an "end date" datepicker if the user selects a date past the end date from a "start date" datepicker. Now what I have to do is:

foo.datepicker('setDate', newDate);
foo.datepicker('options', 'onSelect')(newDate);

comment:2 Changed 11 years ago by Scott González

Type: enhancementfeature

comment:3 Changed 10 years ago by Jasmine

Just wanted to add that as long as you don't need the first parameter (the date as a string), then an alternative workaround is to add a standard jQuery 'change' handler to foo that calls the same function that datepicker's onSelect does.

Then it could be done by

foo.datepicker('setDate', newDate);

Not ideal by any measure, I actually like enbergj's workaround better as it keeps it all in onSelect, but this way may be easier for other developers to remember if you are working on a team.

comment:4 Changed 10 years ago by Scott González


comment:5 Changed 10 years ago by mikesherov

Status: newopen

comment:6 Changed 10 years ago by omnidev

enbergj's method didn't work for me because my onSelect handler needed access to the inst object that is passed internally to that event handler. I needed to be able to pass get the internal datepicker instance so I made a function to get it.

Function to get the internal instance object of a datepicker element:

I believe there has to be a better way, but if you just need something that'll do the job, this is it until you find something better.

Last edited 10 years ago by omnidev (previous) (diff)

comment:7 Changed 10 years ago by Desty Nova

See this stackoverflow thread:


is way more simple, though relying on the class used by jquery ui for the current day in calendar

Last edited 10 years ago by Desty Nova (previous) (diff)

comment:8 Changed 9 years ago by dsoprea

Has there been any progress on this. It seems like a reasonable functionality. I couldn't believe that this wasn't default behavior until I verified it.

comment:9 Changed 9 years ago by Scott González

Milestone: 1.11.0none
Note: See TracTickets for help on using tickets.