I have a page that has two input fields that utilize Jquery UI autocomplete and I want their functionality to mirror each other. I've added a class to each item the dropdown results to change the background color based on this: https://stackoverflow.com/a/18813136/5473973. The autocomplete functionality will work on both inputs properly but when searching on the 2nd search box, the styling class is not added to the results resulting in a white background. It is only applying to the class to the first search box's set of results. How do I apply this styling to both (all) the autocomplete search box's results on the page?
These are the search fields:
<input class="autocomplete-test" id="search1" type="text" data-autocomplete-url="URLToGetInfoHere" />
<input class="autocomplete-test" id="search2" type="text" data-autocomplete-url="URLToGetInfoHere"/>
And this is the auto complete:
$(".autocomplete-test").autocomplete({
source: $(".autocomplete-test").attr("data-autocomplete-url")
}).data("ui-autocomplete")
._renderItem = function (ul, item) {
var listItem = $("<li></li>")
.data("item.autocomplete", item)
.append("<a>" + item.label + "</a>")
.appendTo(ul);
if (item.IsEligible) {
listItem.addClass("eligible");//Change BG color to green
}
else {
listItem.addClass("ineligible")//Change BG color to red
}
return listItem;
};