From 7444fd95e25b232254608ae3326f2d199afcbd7a Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Mon, 11 Oct 2010 10:07:11 +0000 Subject: [PATCH] Fix: auto selected if only one record --- htdocs/lib/ajax.lib.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/htdocs/lib/ajax.lib.php b/htdocs/lib/ajax.lib.php index 4fbda426200..a40e9129094 100644 --- a/htdocs/lib/ajax.lib.php +++ b/htdocs/lib/ajax.lib.php @@ -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"),"$1"); - 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"),"$1"); + return { label: label, value: item.value, id: item.key} + } })); }, "json"); },