Fix: auto selected if only one record

This commit is contained in:
Regis Houssin 2010-10-11 10:07:11 +00:00
parent e3a1f317a8
commit 7444fd95e2

View File

@ -92,8 +92,13 @@ function ajax_autocompleter($selected='',$htmlname,$url,$option='')
source: function( request, response ) {
jQuery.get("'.$url.($option?'?'.$option:'').'", { '.$htmlname.': request.term }, function(data){
response( jQuery.map( data, function( item ) {
var label = item.label.toString().replace(new RegExp("("+request.term+")","i"),"<strong>$1</strong>");
return { label: label, value: item.value, id: item.key}
if (data.length == 1) {
jQuery("#search_'.$htmlname.'").val(item.value);
jQuery("#'.$htmlname.'").val(item.key);
} else {
var label = item.label.toString().replace(new RegExp("("+request.term+")","i"),"<strong>$1</strong>");
return { label: label, value: item.value, id: item.key}
}
}));
}, "json");
},