5

This question is similar to Check if datepicker is open except that it pertains to a page that has multiple datepicker controls on it.

When there are multiple datepickers on a page, jQuery UI appears to only create one datepicker widget that is shared between all of the datepickers.

I am attempting to find a way, through the datepicker UI or otherwise, to find out which datepicker the widget is open for. Unfortunately the tried and true tests such as:

$('#someDatepicker').datepicker('widget').is(':visible');

return true regardless of which datepicker the widget is open for, as long as it is visible somewhere.

Community
  • 1
  • 1
jbabey
  • 44,525
  • 12
  • 67
  • 94
  • 1
    The only suggestion I could give is to use the `beforeShow` event to capture the element that the datepicker belongs to and store it as a global variable. There doesn't seem to be a sensible way to find the owner of the dialog... http://api.jqueryui.com/datepicker/#option-beforeShow – Reinstate Monica Cellio May 21 '13 at 15:56

1 Answers1

6

After crawling through the source code for datepicker I found some related code around line 718:

inst = $.datepicker._getInst(input);
if ($.datepicker._curInst && $.datepicker._curInst !== inst) {
    ...
}

Using this code I dug a little more into these internal objects and whipped up a fiddle. It looks like the $.datepicker._curInst.id will give you the ID of the textbox that the datepicker widget is open for.

Use at your own risk, as the object is internal and undocumented and could be changed/moved/removed in future versions of the library.

jbabey
  • 44,525
  • 12
  • 67
  • 94
  • Due to the current instance being re-assigned upon calling $selector.datepicker('refresh') I ended up using $.datepicker._curInst.id to determine which datepicker actually needs refreshing. – Olivier Apr 04 '17 at 15:12