1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
$("#tags").autocomplete({
minLength: 2,
source: function(req, add){
var suggestions = [];
//J'insère ma ligne par défaut...
suggestions.push({
"id": 0,
"libelle": "NOUVEAU PATIENT"
});
add(suggestions);
//S'il faut faire une requete, et ben on la fait...
if(req != "creer_nouveau_patient") {
$.getJSON("modules/accueil/rechercheRpc.php?callback=?", req, function(data) {
$.each(data, function(i, val){
suggestions.push({
"id": val.id,
"libelle": val.libelle
});
});
add(suggestions);
});
}
},
select: function(e, ui) {
$("#id_patient").val(ui.item.id);
var page = (ui.item.id == 0) ? "index.php?module=patient&action=edition_patient" : "index.php?module=patient&action=patient";
$("#recherche_patient").attr("action", page);
$("#recherche_patient").submit();
},
change: function() {
$("#tags").val("").css("top", 2);
}
}).data( "autocomplete" )._renderItem = function( ul, item ) {
return $( "<li></li>" )
.data( "item.autocomplete", item )
.append( "<a style='font-size: 80%;'>" + item.libelle + "</a>" )
.appendTo( ul );
}; |
Partager