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.= '