Skip to main content

Search and Top Navigation

#3235 closed bug (fixed)

Opened August 20, 2008 07:01AM UTC

Closed August 21, 2008 04:19PM UTC

Last modified October 11, 2012 09:15PM UTC

datepicker id generation not unique; with patch

Reported by: mattwallace Owned by: grabanski
Priority: minor Milestone:
Component: ui.datepicker Version: 1.6b
Keywords: Cc: matt@daz3d.com
Blocked by: Blocking:
Description

Datepicker automatically assigns ids when one is not present. However, it uses new Date().getTime(), which only is granular to the millisecond level. However, calling the datepicker instantiation method on a class, ie, $("div.calpick").datepicker({ selectRange: false });, or such, can easily result in the datepicker trying to assign the same id because it handles more than 1 per millisecond.

This patch creates a .uuid variable in the singleton and assigns its incremented value as an addition to the Date().getTime() call; although I imagine you could probably get rid of the getTime call entirely, but I left it in. I tested this and it worked fine resolving my issue.

Although I am using a personalized bundle, I added a couple lines of context to this diff to make it clear where I changed lines:

*** jquery-ui.js        Tue Aug 19 17:06:08 2008
--- /tmp/jquery-ui-personalized-1.6b.js Fri Aug 15 15:51:54 2008
***************
*** 2366,2370 ****
                var inline = (nodeName == 'div' || nodeName == 'span');
                if (!target.id)
!                       target.id = 'dp' + new Date().getTime() + ++$.datepicker.uuid;
                var inst = this._newInst($(target), inline);
                inst.settings = $.extend({}, settings || {}, inlineSettings || {});
--- 2366,2370 ----
                var inline = (nodeName == 'div' || nodeName == 'span');
                if (!target.id)
!                       target.id = 'dp' + new Date().getTime();
                var inst = this._newInst($(target), inline);
                inst.settings = $.extend({}, settings || {}, inlineSettings || {});
***************
*** 2460,2464 ****
                var inst = this._dialogInst; // internal instance
                if (!inst) {
!                       var id = 'dp' + new Date().getTime() + ++$.datepicker.uuid;
                        this._dialogInput = $('<input type="text" id="' + id +
                                '" size="1" style="position: absolute; top: -100px;"/>');
--- 2460,2464 ----
                var inst = this._dialogInst; // internal instance
                if (!inst) {
!                       var id = 'dp' + new Date().getTime();
                        this._dialogInput = $('<input type="text" id="' + id +
                                '" size="1" style="position: absolute; top: -100px;"/>');
***************
*** 3868,3872 ****
  $.datepicker = new Datepicker(); // singleton instance
  $.datepicker.initialized = false;
- $.datepicker.uuid = 0; // for creating unique identifiers

  })(jQuery);
--- 3868,3871 ----
Attachments (0)
Change History (3)

Changed August 20, 2008 07:04AM UTC by mattwallace comment:1

My bad! I submitted the diff backwards.

Forwards diff:

*** /tmp/jquery-ui-personalized-1.6b.js Fri Aug 15 15:51:54 2008
--- jquery-ui.js        Tue Aug 19 17:06:08 2008
***************
*** 2366,2370 ****
                var inline = (nodeName == 'div' || nodeName == 'span');
                if (!target.id)
!                       target.id = 'dp' + new Date().getTime();
                var inst = this._newInst($(target), inline);
                inst.settings = $.extend({}, settings || {}, inlineSettings || {}); 
--- 2366,2370 ----
                var inline = (nodeName == 'div' || nodeName == 'span');
                if (!target.id)
!                       target.id = 'dp' + new Date().getTime() + ++$.datepicker.uuid;
                var inst = this._newInst($(target), inline);
                inst.settings = $.extend({}, settings || {}, inlineSettings || {}); 
***************
*** 2460,2464 ****
                var inst = this._dialogInst; // internal instance
                if (!inst) {
!                       var id = 'dp' + new Date().getTime();
                        this._dialogInput = $('<input type="text" id="' + id +
                                '" size="1" style="position: absolute; top: -100px;"/>');
--- 2460,2464 ----
                var inst = this._dialogInst; // internal instance
                if (!inst) {
!                       var id = 'dp' + new Date().getTime() + ++$.datepicker.uuid;
                        this._dialogInput = $('<input type="text" id="' + id +
                                '" size="1" style="position: absolute; top: -100px;"/>');
***************
*** 3868,3871 ****
--- 3868,3872 ----
  $.datepicker = new Datepicker(); // singleton instance
  $.datepicker.initialized = false;
+ $.datepicker.uuid = 0; // for creating unique identifiers
  
  })(jQuery);

Changed August 21, 2008 04:19PM UTC by kbwood comment:2

resolution: → fixed
status: newclosed

Fixed. Start with current time in milliseconds and then increment for each ID.

Changed October 11, 2012 09:15PM UTC by scottgonzalez comment:3

milestone: TBD

Milestone TBD deleted