diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 35e8d82447d..2994eacd947 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -564,7 +564,7 @@ class Form { print ''; } - print ajax_autocompleter(($socid?$socid:-1),$htmlname,'socname',DOL_URL_ROOT.'/societe/ajaxcompanies.php?filter='.urlencode($filter), ''); + print ajax_autocompleter(($socid?$socid:-1),$htmlname,DOL_URL_ROOT.'/societe/ajaxcompanies.php?filter='.urlencode($filter), ''); print ''; print ''; print ''; @@ -862,11 +862,11 @@ class Form if ($conf->global->MAIN_USE_NEW_JQUERY) { // mode=1 means customers products - print ajax_autocompleter2('',$htmlname,DOL_URL_ROOT.'/product/ajaxproducts.php','outjson=1&price_level='.$price_level.'&type='.$filtertype.'&mode=1&status='.$status.'&finished='.$finished,''); + print ajax_autocompleter('',$htmlname,DOL_URL_ROOT.'/product/ajaxproducts.php','outjson=1&price_level='.$price_level.'&type='.$filtertype.'&mode=1&status='.$status.'&finished='.$finished,''); print '
'; - print ''; - print ''; + print ''; + print ''; print '
'; } else diff --git a/htdocs/core/class/html.formcompany.class.php b/htdocs/core/class/html.formcompany.class.php index 36dffc0e6c4..e7d7ef6d7ad 100644 --- a/htdocs/core/class/html.formcompany.class.php +++ b/htdocs/core/class/html.formcompany.class.php @@ -545,7 +545,7 @@ class FormCompany { print ''; } - print ajax_autocompleter(($socid?$socid:-1),$htmlname,'socname',DOL_URL_ROOT.'/societe/ajaxcompanies.php',''); + print ajax_autocompleter(($socid?$socid:-1),$htmlname,DOL_URL_ROOT.'/societe/ajaxcompanies.php',''); print ''; print ''; print ''; diff --git a/htdocs/lib/ajax.lib.php b/htdocs/lib/ajax.lib.php index 6c50866b7ff..4fbda426200 100644 --- a/htdocs/lib/ajax.lib.php +++ b/htdocs/lib/ajax.lib.php @@ -80,7 +80,7 @@ function ajax_updater($htmlname,$keysearch,$url,$option='',$indicator='working') * \param url chemin du fichier de reponse : /chemin/fichier.php * \return string script complet */ -function ajax_autocompleter($selected='',$htmlname,$valname,$url) +function ajax_autocompleter($selected='',$htmlname,$url,$option='') { $script=''; @@ -90,10 +90,10 @@ function ajax_autocompleter($selected='',$htmlname,$valname,$url) $script.= 'jQuery(document).ready(function() { jQuery("input#search_'.$htmlname.'").autocomplete({ source: function( request, response ) { - jQuery.get("'.$url.'", { '.$htmlname.': request.term }, function(data){ + jQuery.get("'.$url.($option?'?'.$option:'').'", { '.$htmlname.': request.term }, function(data){ response( jQuery.map( data, function( item ) { - var label = item.'.$valname.'.toString().replace(new RegExp("("+request.term+")","i"),"$1"); - return { label: label, value: item.'.$valname.', id: item.'.$htmlname.'} + var label = item.label.toString().replace(new RegExp("("+request.term+")","i"),"$1"); + return { label: label, value: item.value, id: item.key} })); }, "json"); }, diff --git a/htdocs/product/ajaxproducts.php b/htdocs/product/ajaxproducts.php index 423daf690cf..30fd07015e4 100644 --- a/htdocs/product/ajaxproducts.php +++ b/htdocs/product/ajaxproducts.php @@ -50,16 +50,16 @@ $langs->load("main"); //top_htmlhead("", "", 1); // Replaced with top_httphead. An ajax page does not need html header. top_httphead(); -print ''."\n"; +//print ''."\n"; //print ''."\n"; dol_syslog(join(',',$_POST)); -if (! isset($_GET['keysearch']) && ! isset($_GET['term'])) return; +if (! isset($_GET['keysearch']) && ! isset($_GET['idprod'])) return; // When used from jQuery, the search term is added as GET param "term". -$searchkey=isset($_GET['keysearch'])?$_GET['keysearch']:$_GET['term']; +$searchkey=isset($_GET['keysearch'])?$_GET['keysearch']:$_GET['idprod']; $outjson=isset($_GET['outjson'])?$_GET['outjson']:0; // Get list of product. diff --git a/htdocs/societe/ajaxcompanies.php b/htdocs/societe/ajaxcompanies.php index d5729207e7b..544c50a7347 100644 --- a/htdocs/societe/ajaxcompanies.php +++ b/htdocs/societe/ajaxcompanies.php @@ -80,8 +80,9 @@ if (! empty($_GET['newcompany']) || ! empty($_GET['socid']) || ! empty($_GET['id if ($resql) { while ($row = $db->fetch_array($resql)) { - $row_array['socname'] = $row['nom']; - $row_array['socid'] = $row['rowid']; + $row_array['label'] = $row['nom']; + $row_array['value'] = $row['nom']; + $row_array['key'] = $row['rowid']; array_push($return_arr,$row_array); }