I have the following code below and I have to make sure that when I click on the autocomplete result, and it fills the field with the values, the autocomplete list simply disappears:
<pre>
<style>
ul.autocomplete_mapa_filter{
list-style: none;
display:block;
float:left;
position:absolute;
top:20;
z-index:999;
border:1px solid #eeeeee;
background:#ffffff;
box-shadow: 1px 1px 2px #444;
}
ul.autocomplete_mapa_filter li{
display:block;
padding:5px 0;
line-height:30px;
border-bottom: 1px solid #eeeeee;
width:400px;
cursor:pointer;
}
ul.autocomplete_mapa_filter li:hover{
background: #f4f4f4;
}
ul.autocomplete_mapa_filter li img{
margin-left:5px;
width:50px;
height:50px;
float:left;
}
ul.autocomplete_mapa_filter li span{
margin-top:5px;
margin-left:1px;
}
</style>
<script type="text/javascript">
$(function () {
$('#mapa_filter').keyup(function () {
var mapa_filter = $(this).val();
$.post('<?= INCLUDE_PATH; ?>/modulos/autocomplete_mapa_filter.php',
{search: mapa_filter},
function (retorno) {
$('.autocomplete_mapa_filter').html(retorno);
});
});
$('.autocomplete_mapa_filter').delegate('li', 'click', function () {
var texto_filter = $(this).text();
$('#mapa_filter').val(texto_filter);
/**estas linhas abaixo eu coloquei pra tentar fazer sumir após clicar fora, ou quando clicar no item, mais sem sucesso*/
texto_filter.click(function () {
texto_filter.hide();
if (!$(this).closest('li').length) $('.autocomplete_mapa_filter').removeClass("li");
});
});
});
</script>
</pre>