When using the autocomplete of Jquery Ui I have had a small problem. I am performing an ajax search to feed a text field. In this field a discipline is searched for and the autocomplete mounts the auto-suggestion menu.
The search and presentation of the data works correctly. The problem is autocomplete does the search once or does not refresh the data refinement when one or more characters are added for example:
Eg,ifIsearchtheBANandBANKOFDATAandKANBANisdisplayedasresults.IfIaddonemorecharacterandformBAN,thesuggestionmenuisnothidden(sincenodatawasfound).IfIaddonemorecharacterandformBANCtheKANBANoptionisnothidden
Inshort,onthethirdcharacterthesearchisdone,however,whenanewcharacterisaddedtheauto-suggestionmenuisnotupdated.
Ihavethefollowingcode:
HTML
<inputtype="text" id="nm">
JQUERY
$("#nm").autocomplete({
minLength:3,
source: function(request,response){
$.post({
url:'getDisciplina.php',
dataType:'json',
data:{'term':request.term},
}).done(function(data){
response($.map(data,function(item){
return({
label: item.label,
value: item.label,
id: item.value,
});
}));
});
},
getDiscipline.php
public function getDisciplina(){
$data = (isset($_POST['term']))?$_POST['term']:false;
$model = new DisciplinaModel;
$rs = $model->getDisciplina($data);
$arr = [];
if($rs){
foreach ($rs as $r){
array_push($arr,["label"=>$r->descr,"value"=>$r->descr,"id"=>$r->id]);
}
print_r(json_encode($arr));
}
else{
print_r(false);
}
//Retorna algo como:[{"label":"Banco de Dados I","value":"2"},{"label":"Kanban","value":"3"}]