From b77ef8c2d6a4ffc3a5f54cc7a93b52ad601bd80c Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 27 Oct 2010 09:00:37 +0000 Subject: [PATCH] Fix: ajax_autocompleter is used by another modules --- htdocs/core/class/html.form.class.php | 6 ++++-- htdocs/core/class/html.formcompany.class.php | 4 +++- htdocs/lib/ajax.lib.php | 13 +++---------- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 93c1f062dc9..ef6cfbfcb0c 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -515,7 +515,9 @@ class Form { if ($conf->use_javascript_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT && ! $forcecombo) { - $socid = 0; + $minLength = (is_numeric($conf->global->COMPANY_USE_SEARCH_TO_SELECT)?$conf->global->COMPANY_USE_SEARCH_TO_SELECT:2); + + $socid = 0; if ($selected) { $obj = $this->db->fetch_object($resql); @@ -533,7 +535,7 @@ class Form { print ''; } - print ajax_autocompleter(($socid?$socid:-1),$htmlname,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), '', $minLength); print ''; print ''; print ''; diff --git a/htdocs/core/class/html.formcompany.class.php b/htdocs/core/class/html.formcompany.class.php index cdc2072aebb..307f39b0be9 100644 --- a/htdocs/core/class/html.formcompany.class.php +++ b/htdocs/core/class/html.formcompany.class.php @@ -522,6 +522,8 @@ class FormCompany { if ($conf->use_javascript_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT) { + $minLength = (is_numeric($conf->global->COMPANY_USE_SEARCH_TO_SELECT)?$conf->global->COMPANY_USE_SEARCH_TO_SELECT:2); + $socid=0; if ($selected) { @@ -546,7 +548,7 @@ class FormCompany { print ''; } - print ajax_autocompleter(($socid?$socid:-1),$htmlname,DOL_URL_ROOT.'/societe/ajaxcompanies.php',''); + print ajax_autocompleter(($socid?$socid:-1),$htmlname,DOL_URL_ROOT.'/societe/ajaxcompanies.php','',$minLength); print ''; print ''; print ''; diff --git a/htdocs/lib/ajax.lib.php b/htdocs/lib/ajax.lib.php index 760aba0c5e8..691b3de54f0 100644 --- a/htdocs/lib/ajax.lib.php +++ b/htdocs/lib/ajax.lib.php @@ -31,16 +31,9 @@ * @param url chemin du fichier de reponse : /chemin/fichier.php * @return string script complet */ -function ajax_autocompleter($selected='',$htmlname,$url,$option='') +function ajax_autocompleter($selected='',$htmlname,$url,$option='',$minLength=2) { - global $conf; - - if (empty($conf->global->COMPANY_USE_SEARCH_TO_SELECT)) return "COMPANY_USE_SEARCH_TO_SELECT is empty. This should not happens"; - if (! is_numeric($conf->global->COMPANY_USE_SEARCH_TO_SELECT)) return "COMPANY_USE_SEARCH_TO_SELECT is not a numeric. This should not happens"; - - $script=''; - - $script.= ''; + $script = ''; $script.= '