Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set the z-index value of a jQuery autocomplete input a level above the result list itself

The default behavior for the jQuery Autocomplete widget is to position the results list one z-index level above the input so that the latter is always visible but in my case this has the undesirable effect of overshadowing the text input element.

I tried to set the z-index value input element at least one level above that of the result list from within the open method like so without much success:

open: function () {
    setTimeout(function () {
        $(this).css('zIndex', 10000);
    }, 1);
},
close: function () {
    $(this).css('zIndex', 0);
}

The z-index level for the input element does get promoted to 10000 while that of the results list remains at level 1 but the input element still appears underneath it.

Does anyone have a clue on why this is happening? The position attributes for the results list and input element are set to absolute and relative respectively. Could that be the cause?

like image 378
Ziad Avatar asked Aug 23 '12 11:08

Ziad


People also ask

What is Z index in jQuery?

The zIndex property sets or returns the stack order of a positioned element. An element with greater stack order (1) is always in front of another element with lower stack order (0). Tip: A positioned element is an element with the position property set to: relative, absolute, or fixed.

How do you find the value of autocomplete?

The AutoComplete control supports strongly-typed HTML helpers represented by lambda expressions that have model or template passed into the View. So, you can get the selected value from view in the Controller part. To achieve this, create an AutocompleteFor control and bound the dataSource from controller part.

How to control z index CSS?

To control an element with the z-index property, the element must have a value for position that is not static (the default). z-index will apply to elements with a position of relative, fixed, absolute, or sticky. To learn more about how the CSS position property works, see our intro guide to CSS position.


1 Answers

You can do it by adding a simple rule to your styleseet:

#your_input {
    position: relative;
    z-index: 10000;
}
.ui-autocomplete {
     z-index: 9999 !important;
}

That should do all the work, I tested it in the firebug

like image 168
Dmitry Koroliov Avatar answered Oct 15 '22 01:10

Dmitry Koroliov