I don't know why if I have only one text field for categories the autocomplete is working (i can see suggested fill when user is typing in that categories text input box) but when I want to use more than one field let's say for subcategories it's not working on both (suggestions are not displaying)... Please help
<script type="text/javascript">
$.getJSON( {{ route('search.categories') }}, function( data ) {
var categories = data.map(function(val){
return val.title;
});
auto(categories);
});
$.getJSON( {{ route('search.subcategories') }}, function( data ) {
var subcategories = data.map(function(val){
return val.title;
});
auto(subcategories);
});
function auto(categories){
$("#category_input").autocomplete({
source: categories,
minLength: 2
});
}
function auto(subcategories){
$("#subcategory_input").autocomplete({
source: subcategories,
minLength: 2
});
}
</script>
View:
<input type="text" id="category_input" />
<input type="text" id="subcategory_input"/>
auto). More specifically, the second one overwrites the first one.