Jquery date picker z-index issue
Asked Answered
W

16

111

I have a slideshow div, and I have a datepicker field above that div.

When I click in the datepicker field, the datepicker panel show behind slideshow div.

And I have put the script as:

http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.14/jquery-ui.min.js

So I cannot change the z-index of datepicker in CSS. The z-index of datepicker which the script is generating is 1 and my slideshow div(also calling thru googleajaxapi) z-index is 5. So I guess I have to increase the z-index of date picker greater than 5. So is there any way to increase it ?

Someone can help me?

Warring answered 11/8, 2011 at 21:58 Comment(1)
Here is the solution #11533661Bastinado
C
183

Put the following style at the 'input' text element: position: relative; z-index: 100000;.

The datepicker div takes the z-index from the input, but this works only if the position is relative.

Using this way you don't have to modify any javascript from jQuery UI.

Cynthia answered 2/1, 2012 at 19:53 Comment(8)
Problem with this is that your input will display above other elements, this is rarely the desired effectKingsbury
Is that supposed to work when datepicker is bound to a span?Cutinize
position : relative is not acceptable and does not work in my situation. the solution bellow works fine.Centriole
this is not working on IE 11 browser. Is this browser specific?Interosculate
This solution, while it does work, is not valid for all situations. Best is to overide with a single line of CSS '.ui-datepicker{ z-index: 9999 !important;}'Hobbs
It worked for me. I had an issue with IE11: my datepicker were rendered under the overlay containing the input fields. This solution resolved everything.Dentist
I've use : $('.picker').appendTo('body');Steal
For appended bootstrap input fields using 'input-group' this does work but needs to be on the parent <div> that has the input-group classLippi
W
156

simply in your css use '.ui-datepicker{ z-index: 9999 !important;}' Here 9999 can be replaced to whatever layer value you want your datepicker available. Neither any code is to be commented nor adding 'position:relative;' css on input elements. Because increasing the z-index of input elements will have effect on all input type buttons, which may not be needed for some cases.

Woehick answered 27/8, 2012 at 11:46 Comment(3)
I had to use datepicker rather than ui-datepickerHermilahermina
JavaScript still uses discontinuous z-indexes, arbitrary stacking contexts, and has cross-browser compatibility issues in 2016? ActionScript 3 FTW (a decade ago, and still today).Plankton
still works, incorporated to a WordPress site just added in theme style.cssDaria
A
17

worked for me

.hasDatepicker {
    position: relative;
    z-index: 9999;
}
Anadiplosis answered 18/4, 2013 at 22:36 Comment(0)
I
15

Based in marksyzm answer, this worked for me:

$('input').datepicker({
    beforeShow:function(input) {
        $(input).css({
            "position": "relative",
            "z-index": 999999
        });
    }
});
Infecund answered 3/4, 2013 at 16:15 Comment(2)
But this only affects the input and not the datepicker overlay?Britzka
I'm using this example jqueryui.com/datepicker which it doesn't use an icon for the datepicker. With this solution I didn't have problems with the rest of web components.Infecund
T
8

I have a dialog box that uses the datepicker on it. It was always hidden. When I adjusted the z-index, the field on the lower form always showed up on the dialog.

I used a combination of solutions that I saw to resolve the issue.

$('.ui-datepicker', $form).datepicker({
                showButtonPanel: true,
                changeMonth: true,
                changeYear: true,
                dateFormat: "yy-M-dd",
                beforeShow: function (input) {
                    $(input).css({
                        "position": "relative",
                        "z-index": 999999
                    });
                },
                onClose: function () { $('.ui-datepicker').css({ 'z-index': 0  } ); }                    
            });

The before show ensures that datepicker always is on top when selected, but the onClose ensures that the z-index of the field gets reset so that it doesn't overlap on any dialogs opened later with a different datepicker.

Tenancy answered 30/1, 2018 at 16:2 Comment(1)
This solution is great and solved my problem. But edit it a little bit on "onClose" part. I put $(this) instead of $('.ui-datepicker'). So, it will set z-index:0 to the "this input" instead of all inputs with ui-datepicker class.Ataxia
B
5

Adding to Justin's answer, if you're worried about untidy markup or you don't want this value hard coded in CSS you can set the input before it is shown. Something like this:

$('input').datepicker({
    beforeShow:function(input){
        $(input).dialog("widget").css({
            "position": "relative",
            "z-index": 20
        });
    }
});

Note that you cannot omit the "position": "relative" rule, as the plugin either looks in the inline style for both rules or the stylesheet, but not both.

The dialog("widget") is the actual datepicker that pops up.

Britzka answered 21/3, 2013 at 15:47 Comment(1)
This problem should be addressed in the JqueryUI scripts and be set to prevent overlays by default. Majority of usage cases would never want any input overlaying the calendar input capabilities. If there is a need to have input (or other elements) overlay the calendar, then a solution like this should be used. Having said that, @Britzka would be the best solution IMO as you would apply it only when needed.Foreplay
O
5

I had this issue i solved by using on click:

var checkin = $('.dpd1').datepicker()
.on('click', function (ev) {
        $('.datepicker').css("z-index", "999999999");
}).data('datepicker');
Outstretched answered 18/5, 2015 at 9:19 Comment(1)
This solution work perfectly on popup window for me. Thanks !Angelineangelique
B
2

See here: http://forum.jquery.com/topic/z-index-1-datepicker-1-8

Buckels answered 22/10, 2011 at 14:38 Comment(0)
E
1

I have a page where the datepicker was on top of a datatables.net tabletools button. The datatables buttons had a higher z-index than the individual datepicker date buttons. Thanks to Ronye's answer I was able to resolve this problem by using position: relative; and z-index: 10000. Thanks!

Eurasian answered 8/2, 2012 at 17:23 Comment(0)
R
1

This happened to me when I was missing the theme. Make sure the theme exists, or perhaps redownoad the theme, and reupload it to your server.

Roselynroseman answered 8/2, 2012 at 17:32 Comment(0)
B
1

That what solved my problem:

 $( document ).ready(function() {   
    $('#datepickerid').datepicker({
     zIndexOffset: 1040 #or any number you want
     });
});
Benzene answered 15/5, 2016 at 10:13 Comment(0)
G
1

In fact you can effectively add in your css .ui-datepicker{ z-index: 9999 !important;} but you can modify jquery-ui.css or jquery-ui.min.css and add at the end of the ui-datepicker class z-index: 9999 !important;. both things work for me (You only need one ;-))

Gove answered 22/5, 2017 at 19:19 Comment(0)
C
1

I had to

.datepicker.dropdown-menu {
    position: relative;
    z-index: 9999 !important;
}
Cabretta answered 20/8, 2017 at 17:2 Comment(0)
B
0

I had this issue as well, since the datepicker uses the input's z-index, I added the following css

#dialogID input,.modal-dialog input, .modal-dialog .input-group .form-control{
  z-index:inherit;
}

Just take the rule that applies to yours, either by parent id, class, or in my case a bootstrap dialog, using their input-group and form-control.

Beestings answered 7/4, 2017 at 12:30 Comment(0)
J
0

30 puls try
Last I get it. Working

.modal {
    z-index: 1040; // Bootstrap 3 Model
}
.ui-datepicker {
    z-index: 1041 !important;
}
Jacquelynejacquelynn answered 27/11, 2023 at 16:32 Comment(0)
B
0

The problem for me was that the datepicker takes the z-index from the closest parent which has a z-index and then adds +1. So let say the closest one with z-index is 1000 so the datepicker gets 1001.

But! When you still have a parent element with an even higher z-index then you will have a problem!

<div style="z-index: 2000">
    <!-- The highest parent has 2000 -->
    <div style="z-index: 1000">
        <!-- the closest parent has 1000 -->
        <input class"datepicker" />
        <!-- your datepicker popup will get 1001 -->
        <!-- but that is too low to go over your outer parent's z-index of 2000 -->
    </div>
</div>

So it is actually a problem with the z-indexes of your parents.

Bingo answered 2/2 at 8:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.