Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell which datepicker the widget is open for

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.

like image 689
jbabey Avatar asked May 21 '13 15:05

jbabey


People also ask

How do I know if my Datepicker is loaded?

You can check to see if the datepicker script has loaded using: if ($. fn. datepicker) { // ... }

How do I make my Datepicker always visible?

Simply call . datepicker() on a div instead of an input. (To display the datepicker embedded in the page instead of in an overlay.) Save this answer.

What is inline Datepicker?

An inline date picker means that the booking calendar is already open when the screen loads. This article will walk you through the quick and easy process of adjusting the standard configuration. EXAMPLE: https://bookthatapp-demo.com/products/piano-lessons. 1. In Shopify Admin, open your current theme.

How do I set Datepicker input?

If you want to set a value for an input type 'Date', then it has to be formatted as "yyyy-MM-dd" (Note: capital MM for Month, lower case mm for minutes). Otherwise, it will clear the value and leave the datepicker empty.


1 Answers

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.

like image 126
jbabey Avatar answered Nov 02 '22 23:11

jbabey