Autocomplete issue into bootstrap modal
Solution 1
The position is right that it is "absolute", while you need to specify this as an option to autocomplete:
$( ".addresspicker" ).autocomplete( "option", "appendTo", ".eventInsForm" );
Where it can anchor the box with the results in any element, I have to stop it from being anchored to the form's class!
Here is a working JsFiddle!.
Solution 2
The above solution talking about the z-index
issue worked:
.ui-autocomplete { z-index:2147483647; }
Make sure you put it before your .js
script responsible for handling the modal AND autocomplete logic.
Solution 3
Check out the appendTo documentation:
When the value is null, the parents of the input field will be checked for a class of ui-front. If an element with the ui-front class is found, the menu will be appended to that element.
So just add the class "ui-front" to the parent element and the autocomplete will be correctly displayed inside the modal.
Solution 4
With add the class "ui-front" to the div parent element and the autocomplete will be correctly displayed inside the PopUp For Me.
Solution 5
The actual issue is that the Bootstrap Modal has a higher Z-index than any other element in the page. Thus, auto complete actually works - but it gets hidden behind the dialog.
You just need to add this in any of your added css
files:
.ui-autocomplete {
z-index:2147483647;
}
![Lughino](https://i.stack.imgur.com/dPSbn.jpg?s=256&g=1)
Lughino
Always passionate about of computing and solving logic problems. In recent years I have gained experience in leadership in medium sized team. From the development side, I discovered a love for the MEAN stack, where the coupled javascript server side and NoSQL technologies have been adopted in all my projects.
Updated on July 05, 2022Comments
-
Lughino almost 2 years
I have a display problem in the jQuery autocomplete inside a modal dialog bootstrap.
When I mouse scroll, the results do not remain attached to the input.
Is there a way to solve this?
Here JsFiddle:
.ui-autocomplete-input { border: none; font-size: 14px; width: 300px; height: 24px; margin-bottom: 5px; padding-top: 2px; border: 1px solid #DDD !important; padding-top: 0px !important; z-index: 1511; position: relative; }
EDIT I found the problem:
.ui-autocomplete { position: fixed; ..... }
If the modal has scroll the issue remains!
Here JsFiddle/1.
-
Lughino about 11 yearsThe problem is not just that and not solve anything by putting a parameter z-index so high! The problem is not only the fact that it remains below the modal, but if you make it scroll the page the results do not remain attached to the input, and if you re-read the question well will be explained. However, the problem is resolved, see answer above!
-
Lughino almost 11 yearsIf you read the comments of the other answer, which is exactly the same as yours, the problem is not solved in this way!
-
KingOfHypocrites over 9 yearsWorked for me. Regardless of the nay-sayer.
-
Dean Richardson over 8 yearsWorks great with Foundation 5 reveal-modal.
-
z3d0 over 8 yearsThank you. If anyone had my same issue, it applies also to jquery autocomplete combobox. Just add
appendTo: ".your-form-in-modal"
to.autocomplete({
in the_createAutocomplete
function. -
Sagar Gala over 8 yearsThanks for the solution. However if you remove the textarea, We do see a scrollbar inside modal-body. Any idea how to fix this? Here is a working fiddle: jsfiddle.net/TtxqG/410
-
gtzinos about 8 yearsThis is not responsive design
-
Ange Kouakou almost 8 yearsI don't get you @gtzinos
-
cman77 over 7 yearsWhile the accepted answer will work, I feel like this should be the correct answer, as the docs indicate this as the default behavior:
If an element with the ui-front class is found, the menu will be appended to that element
-
teran over 7 yearsor simply add
.ui-front
to modal window -
tomsihap over 7 yearsteran : This is the quickest answer, thanks ! More accurate, add
.ui-front
to your.modal-body
div. -
Koushik Das over 6 yearsPerfect. No JS. With CSS, this is the best solution.
-
Jose Jet almost 6 yearsIf indicating appendTo option does not resolve your issue, you can do
appendTo: $(id or class).parent()
-
CXJ about 5 yearsDoes not work for me. So far, the only thing which does work is hacking the
z-index
which feels wrong. -
Sakhawat Hossain almost 5 yearsYour solutions worded for me too. Thank you
-
fustaki almost 5 yearsNice. if you're using the same function for different cases this could be a general solution:
appendTo: $(selector).closest('form')
-
Mario Orlandi over 4 years@teran: "simply add .ui-front to modal window" this is amazing ! thank you
-
YSFKBDY almost 4 yearsWorked like a charm!
-
Leandro Bardelli over 3 yearsthis should be the answer
-
Leandro Bardelli over 3 yearsyou repeat an already answer 2 years later. See original answer from @Fernando Pinheiro
-
Mark Rotteveel over 3 yearsPlease don't post only code as answer, but also provide an explanation what your code does and how it solves the problem of the question. Answers with an explanation are usually more helpful and of better quality, and are more likely to attract upvotes.