Pixelastic

You can cut our wings but we will always remember what it was like to fly.

Setting the z-index of a jQuery UI datepicker

I ran into a collision issue with two of my absolutly positionned elements on a form page. I had an invisible flash buttun (used to launch an upload process) as well as jQuery UI datepicker.

The form was built in a way that when the datepicker was displayed, it was supposed to be on top of the invisible Flash button. Unfortunatly the button was in fact "on top" of the datepicker, but being invisible you do not notice it until you click.

This resulted in an upload dialog popping up and many confused users.

The fix

The Flash z-index is fixed in my CSS (10), so I thought that adding a greater z-index to the jQuery UI datepicker in CSS would be enough.

It is not. The jQuery UI datepicker seems to automatically set the z-index to 1, whatever you specified.

I checked the datepicker options, looking for a zIndex key, but found nothing...

I tried the beforeShow event, to manually set the z-index, but it seems that jQuery still update my value to 1 AFTER the event.

So I finally resorted to adding a small timeout to re-add my value after jQuery. This is a bit of a hack but given the context this is the only way I found.

// Set the datepicker zIndex on load
element.datepicker({
[...]
'beforeShow': function(input, datepicker) {
setTimeout(function() {
$(datepicker.dpDiv).css('zIndex', 100);
}, 500);
},
[...]
});

 

Comments

In .ui-datepicker (jquery css) try:
z-index: 9999 !important;

Aidanon 22/3/11
Aidan
I should try that, thanks.

I usually consider using !important a bit of a hack, but it may be better than setting a timeout to define a CSS property.
Timon 23/3/11
Tim
It worked...thanks so much..
TriTramon 10/8/11
TriTram
Thank you :*
ionuton 10/10/11
ionut
Nice. Thank you. But funny, that even after such a long time there still seems to be no solution to this issue.
Thomason 1/2/12
Thomas
To be fair, I never reported the bug to jQuery UI, so the team may not even be aware of the issue, and thus, not working on a fix. Feel free to report it.
Timon 12/2/12
Tim
... and 9 spam blocked

Adding a comment

Leave this field empty, it is only here to defeat spam bots
Will not be published