views:

147

answers:

2

Ok, I'm using the jQuery UI datepicker as a replacement for the terrible AjaxToolkit datepicker, but I've run into an issue.

For some reason, the datepicker's prev/next buttons no longer exhibit the correct behaviour, and instead move from this month (selected as default) to december 1899 for previous and january 1900 for next.

Can anyone suggest why this is happening?

Binding code as follows:

$('.jQueryCalendarComponent').live('click', function() {
    $(this).removeClass('hasDatepicker').datepicker({
    showOn: 'both',
    showAnim: '',
    dateFormat: 'dd/mm/yy',
    buttonImage: 'images/calendar.gif',
    buttonImageOnly: true
    }).focus();
 }).datepicker({
    showOn: 'both',
    showAnim: '',
    dateFormat: 'dd/mm/yy',
    "buttonImage: 'images/calendar.gif',
    buttonImageOnly: true
 });

Live('click') is used in a similar manner to live would be used to attach an event, and .jQueryCalendarComponent is a textbox.

A: 

You don't need to use live for your datepicker. Calling datapicker on the textbox will set up the events for you. Each time you click on the text box you are stacking datepickers on it. This could explain the strange functionality. Try something like:

$('.jQueryCalendarComponent').datepicker({
    showOn: 'both',
    showAnim: '',
    dateFormat: 'dd/mm/yy',
    buttonImage: 'images/calendar.gif',
    buttonImageOnly: true
});
Alistair
UpdatePanel makes it work a little differently: I have to re-bind it at each point in order to have the new textboxes with datepickers. Also, that's why I'm doing the removeClass first, this un-binds the UpdatePanel.
Ed Woodcock
A: 

The previous widget is in effect and getting overriden, this can lead to funny things...try this instead:

$(this).datepicker('destroy').datepicker({
showOn: 'both',
showAnim: '',
dateFormat: 'dd/mm/yy',
buttonImage: 'images/calendar.gif',
buttonImageOnly: true
}).focus();

This destroys the previous widget and re-creates based on current data, removeClass() doesn't clear out everything associated with the date picker, just one attribute it applies...this will clear the widget completely.

Nick Craver
Yeah, you suggested this in a previous question of mine: it simply does't work with lightboxes (specifically the facebox lightbox). It also doesn't resolve the issue in this instance, unfortunately.
Ed Woodcock
@Ed - When you're dealing with an UpdatePanel, need to post that code (or at the very least mention it)...it does horrendous things that really affect the DOM, and has a significant impact on the question.
Nick Craver
Sorry, my bad: it's not just in the updatepanels that the issues occur, so I didn't think it was that relevant -> the prev/next problem occurs everywhere, and the issue with using .datepicker('destory') is to do with lightboxes. The updatepanel only affects the use of the live('click') thing, and I mentioned why I'd done that in the question. And believe me, I'm well aware that UpdatePanels are evil, it's just very hard to get away from them at my current job, everyone else just uses them without thinking.
Ed Woodcock