Hi everybody,
I have this piece of code and I want to show max 5 results and when 5 or more results are shown to have a link that will show the page with all results. I thought something with slice but I don’t know where to implement it and about the link I don;t know at all.
<input type="text" class="input-block-level search-query" name="search2" placeholder="" id="search_query2" value="" />
<i aria-hidden="true" class="icon_close"></i>
<div id="autocomplete-results2" class="autocomplete-results"></div>
<script type="text/javascript">
$(document).ready(function() {
$('#search_query2').autocomplete({
delay: 0,
appendTo: "#autocomplete-results2",
source: function(request, response) {
$.ajax({
url: 'index.php?route=search/autocomplete&filter_name=' + encodeURIComponent(request.term),
dataType: 'json',
success: function(json) {
response($.map(json, function(item) {
return {
label: item.name,
value: item.product_id,
href: item.href,
thumb: item.thumb,
desc: item.desc,
price: item.price
}
}));
}
});
},
select: function(event, ui) {
document.location.href = ui.item.href;
return false;
},
focus: function(event, ui) {
return false;
},
minLength: 2
})
.data( "ui-autocomplete" )._renderItem = function( ul, item ) {
return $( "<li class='ajaxItem' >" )
.append( "<a style='cursor:pointer;'><img src='" + item.thumb + "' alt=''></br>" + item.label + "<br><span class='description'>" + '' + "</span><span class='price'>" + item.price + "</span></a>" )
.appendTo( ul );
};
});
</script>
Thank you