From 6bac74470951d78d33b035b2164d941bab2ede0f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 13 Nov 2014 16:46:40 +0100 Subject: [PATCH] Fix: Missing event management into select when combo not selected --- htdocs/comm/action/card.php | 4 +- htdocs/core/class/html.form.class.php | 65 ++++++++++++++++++-- htdocs/core/class/html.formcompany.class.php | 2 +- htdocs/core/lib/ajax.lib.php | 4 +- 4 files changed, 66 insertions(+), 9 deletions(-) diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php index 96db3133cf9..e67111fad6c 100644 --- a/htdocs/comm/action/card.php +++ b/htdocs/comm/action/card.php @@ -710,9 +710,9 @@ if ($action == 'create') $events[]=array('method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php',1), 'htmlname' => 'contactid', 'params' => array('add-customer-contact' => 'disabled')); //For external user force the company to user company if (!empty($user->societe_id)) { - print $form->select_company($user->societe_id,'socid','',1,1,0,$events); + print $form->select_thirdparty_list($user->societe_id,'socid','',1,1,0,$events); } else { - print $form->select_company('','socid','',1,1,0,$events); + print $form->select_thirdparty_list('','socid','',1,1,0,$events); } } diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 03defa19129..eb2f13c8ac3 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -746,7 +746,7 @@ class Form * @param int $showempty Add an empty field * @param int $showtype Show third party type in combolist (customer, prospect or supplier) * @param int $forcecombo Force to use combo box - * @param array $events Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled'))) + * @param array $events Event options to run on change. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled'))) * @param int $limit Maximum number of elements * @return string HTML string with * @deprecated Use select_thirdparty instead @@ -816,10 +816,67 @@ class Form $resql=$this->db->query($sql); if ($resql) { - if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->COMPANY_USE_SEARCH_TO_SELECT) && ! $forcecombo) + if (! empty($conf->use_javascript_ajax)) { - include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; - $out.= ajax_combobox($htmlname, $events, $conf->global->COMPANY_USE_SEARCH_TO_SELECT); + if (! empty($conf->global->COMPANY_USE_SEARCH_TO_SELECT) && ! $forcecombo) + { + include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; + $out.= ajax_combobox($htmlname, $events, $conf->global->COMPANY_USE_SEARCH_TO_SELECT); + } + else + { + if (count($events)) // Add management of event + { + print ''; + } + } } // Construct $out and $outarray diff --git a/htdocs/core/class/html.formcompany.class.php b/htdocs/core/class/html.formcompany.class.php index d32c0def5ab..e45fffff759 100644 --- a/htdocs/core/class/html.formcompany.class.php +++ b/htdocs/core/class/html.formcompany.class.php @@ -547,7 +547,7 @@ class FormCompany $resql = $this->db->query($sql); if ($resql) { - if ($conf->use_javascript_ajax && ! empty($conf->global->COMPANY_USE_SEARCH_TO_SELECT)) + if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->COMPANY_USE_SEARCH_TO_SELECT)) { // Use Ajax search $minLength = (is_numeric($conf->global->COMPANY_USE_SEARCH_TO_SELECT)?$conf->global->COMPANY_USE_SEARCH_TO_SELECT:2); diff --git a/htdocs/core/lib/ajax.lib.php b/htdocs/core/lib/ajax.lib.php index f21d7d2ff02..3966b29f874 100644 --- a/htdocs/core/lib/ajax.lib.php +++ b/htdocs/core/lib/ajax.lib.php @@ -345,13 +345,13 @@ function ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0) var obj = '.json_encode($events).'; $.each(obj, function(key,values) { if (values.method.length) { - runJsCodeForEvent(values); + runJsCodeForEvent'.$htmlname.'(values); } }); } }); - function runJsCodeForEvent(obj) { + function runJsCodeForEvent'.$htmlname.'(obj) { var id = $("#'.$htmlname.'").val(); var method = obj.method; var url = obj.url;