2
0
forked from Wavyzz/dolibarr

Fix: ajax_autocompleter is used by another modules

This commit is contained in:
Regis Houssin
2010-10-27 09:00:37 +00:00
parent 43ce5a638e
commit b77ef8c2d6
3 changed files with 10 additions and 13 deletions

View File

@@ -515,7 +515,9 @@ class Form
{ {
if ($conf->use_javascript_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT && ! $forcecombo) 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) if ($selected)
{ {
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
@@ -533,7 +535,7 @@ class Form
{ {
print '<input type="text" size="30" id="search_'.$htmlname.'" name="search_'.$htmlname.'" value="'.$obj->nom.'" />'; print '<input type="text" size="30" id="search_'.$htmlname.'" name="search_'.$htmlname.'" value="'.$obj->nom.'" />';
} }
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 '</td>'; print '</td>';
print '</tr>'; print '</tr>';
print '</table>'; print '</table>';

View File

@@ -522,6 +522,8 @@ class FormCompany
{ {
if ($conf->use_javascript_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT) 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; $socid=0;
if ($selected) if ($selected)
{ {
@@ -546,7 +548,7 @@ class FormCompany
{ {
print '<input type="text" size="30" id="search_'.$htmlname.'" name="search_'.$htmlname.'" value="'.$obj->nom.'" '.$htmloption.' />'; print '<input type="text" size="30" id="search_'.$htmlname.'" name="search_'.$htmlname.'" value="'.$obj->nom.'" '.$htmloption.' />';
} }
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 '</td>'; print '</td>';
print '</tr>'; print '</tr>';
print '</table>'; print '</table>';

View File

@@ -31,16 +31,9 @@
* @param url chemin du fichier de reponse : /chemin/fichier.php * @param url chemin du fichier de reponse : /chemin/fichier.php
* @return string script complet * @return string script complet
*/ */
function ajax_autocompleter($selected='',$htmlname,$url,$option='') function ajax_autocompleter($selected='',$htmlname,$url,$option='',$minLength=2)
{ {
global $conf; $script = '<input type="hidden" name="'.$htmlname.'" id="'.$htmlname.'" value="'.$selected.'" />';
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.= '<input type="hidden" name="'.$htmlname.'" id="'.$htmlname.'" value="'.$selected.'" />';
$script.= '<script type="text/javascript">'; $script.= '<script type="text/javascript">';
$script.= 'jQuery(document).ready(function() { $script.= 'jQuery(document).ready(function() {
@@ -66,7 +59,7 @@ function ajax_autocompleter($selected='',$htmlname,$url,$option='')
}, "json"); }, "json");
}, },
dataType: "json", dataType: "json",
minLength: '.$conf->global->COMPANY_USE_SEARCH_TO_SELECT.', minLength: '.$minLength.',
select: function( event, ui ) { select: function( event, ui ) {
jQuery("#'.$htmlname.'").val(ui.item.id); jQuery("#'.$htmlname.'").val(ui.item.id);
} }