Skip to main content

Search and Top Navigation

#5419 closed bug (fixed)

Opened March 24, 2010 05:03PM UTC

Closed February 27, 2013 02:55AM UTC

Calling .datepicker("setDate") during onClose event reopens picker only in IE

Reported by: ladelfa Owned by:
Priority: minor Milestone: 1.8.17
Component: ui.datepicker Version: 1.8
Keywords: setDate onClose Cc:
Blocked by: Blocking:
Description

Calling .datepicker("setDate") inside a onClose event behaves differently in IE7 and IE8 than it does in other browsers.

I tested FF 3.6.2 and Chrome 4.1.249 on WinXP. In those, the date gets set as the picker closes.

In IE 7 and 8 (also WinXP), the date gets set, but the picker reopens itself immediately.

<script>
  $(document).ready(function() {
    $('#picker').datepicker({
      onClose: function(dateText, inst) {
        $('#picker').datepicker("setDate", new Date(2008,7,8));
      }
    });
  });
</script>

<input id='picker' type='text'>

One workaround is to do the setDate after a timeout, but the behavior ought to be consistent across browsers.

Attachments (0)
Change History (7)

Changed April 28, 2010 05:35AM UTC by kbwood comment:1

Why do you need to do this? Having selected a date you then change it to another value.

Changed January 06, 2011 12:29AM UTC by john.firebaugh comment:2

I'm encountering this bug. The test case may look contrived, but there are legitimate reasons to call setDate inside onClose. In my case, I have two datepickers used for selecting a range of time, and one is changed, I may need to call setDate for both -- for example, to handle the case where the begin date is being set to a date later than the currently selected end date. In that situation the two dates need to be swapped in order to maintain the invariant that begin < end.

Changed March 30, 2011 10:15AM UTC by sven_s comment:3

My workaround is to disable and to enable the datepicker:

$(this).datepicker('disable');
$(this).datepicker('setDate', new Date(year1, month1, 1));
$(this).datepicker('enable');

Changed May 24, 2011 01:30PM UTC by Tom Van Schoor comment:4

Thanks for your workaround, i needed it for a month-year picker hack described at:

http://stackoverflow.com/questions/2208480/jquery-date-picker-to-show-month-year-only/6110670#6110670

Ok it is for a hack, but it is pretty darn usefull.

Changed February 27, 2012 03:23PM UTC by jzaefferer comment:5

status: newopen

Changed October 11, 2012 09:04PM UTC by scottgonzalez comment:6

milestone: TBD1.11.0

Changed February 27, 2013 02:55AM UTC by tj.vantoll comment:7

milestone: 1.11.01.8.17
resolution: → fixed
status: openclosed

This was fixed by https://github.com/jquery/jquery-ui/commit/872387abd5ab59e00df108438ae5bba76df1138a which was for #7686.

Version 1.8.16 which shows the bug - http://jsfiddle.net/tj_vantoll/kHWpn/4/.

Version 1.8.17 which shows the bug is no longer present - http://jsfiddle.net/tj_vantoll/kHWpn/5/.

Master, no problems - http://jsfiddle.net/tj_vantoll/kHWpn/.