I have two autocomplete input fields on one page, each calling a different source.
The first input field is rendered on page load. The second autocomplete input field is returned on an ajax call and resides within a bootstrap modal window.
The first autocomplete works just fine:
$("#IdOfFirstInputField").autocomplete({
source: (url),
minLength: 3,
select: function (event, ui) {
alert("It works...");
}
});
The second input field is within a bootsrap modal that has the class ui-front
.
I am binding the autocomplete as such, since it is part of a returned ajax call:
$(document).on("keydown.autocomplete", "#IdForSecondInput", function () {
$(this).autocomplete({
source: (url2),
minLength: 3,
select: function (event, ui) {
alert("It works...");
}
});
});
These custom css styles are being applied to both autocomplete input fields:
.ui-autocomplete {
position: absolute;
z-index: 1000;
cursor: default;
padding: 0;
margin-top: 2px;
list-style: none;
background-color: #ffffff;
border: 1px solid #ccc
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
-webkit-box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
-moz-box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
max-height: 300px;
overflow-y: auto;
overflow-x: hidden;
}
.ui-autocomplete > li {
padding: 3px 20px;
}
.ui-autocomplete > li.ui-state-focus {
background-color: #DDD;
}
.ui-helper-hidden-accessible {
display: none;
}
While the first autocomplete works just as expected, the second one works only to the point that the <ul>
and list item are being attached to the DOM. However, the style of <ul>
is set to display:none;
. If I remove this class through the inspector in the browser of choice, I can see that the list is looking perfectly fine.
Any ideas why the <ul>
element is set to display:none;
after the JSON response is being returned correctly?
It looks like the second input field is losing its focus right after I stop typing within, causing the resulting <ul>
to default to display:none;
.
` element itself. Not for each `- ` element.
– jrn May 25 '18 at 17:10`?
– Rohit.007 May 25 '18 at 17:15` to be hidden.
– jrn May 25 '18 at 17:28` element is instantaneously set to `display: none;`
– jrn May 25 '18 at 17:35` `display: block !important;` if the input is in the focus after focus out you can remove it.
– Rohit.007 May 25 '18 at 17:37