diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php index 96db3133cf9edc1300deffa64e7c4b6a50d369de..e67111fad6caf78827cf36d01a7b52deb1d453bc 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 03defa19129e0f1b79990723b0c20a29656d1ff7..eb2f13c8ac3afb49941ba2ce0fbf99dddc843a53 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 '<script type="text/javascript"> + $(document).ready(function() { + jQuery("#'.$htmlname.'").change(function () { + var obj = '.json_encode($events).'; + $.each(obj, function(key,values) { + if (values.method.length) { + runJsCodeForEvent'.$htmlname.'(values); + } + }); + }); + + function runJsCodeForEvent'.$htmlname.'(obj) { + var id = $("#'.$htmlname.'").val(); + var method = obj.method; + var url = obj.url; + var htmlname = obj.htmlname; + var showempty = obj.showempty; + $.getJSON(url, + { + action: method, + id: id, + htmlname: htmlname, + showempty: showempty + }, + function(response) { + $.each(obj.params, function(key,action) { + if (key.length) { + var num = response.num; + if (num > 0) { + $("#" + key).removeAttr(action); + } else { + $("#" + key).attr(action, action); + } + } + }); + $("select#" + htmlname).html(response.value); + if (response.num) { + var selecthtml_str = response.value; + var selecthtml_dom=$.parseHTML(selecthtml_str); + $("#inputautocomplete"+htmlname).val(selecthtml_dom[0][0].innerHTML); + } else { + $("#inputautocomplete"+htmlname).val(""); + } + $("select#" + htmlname).change(); /* Trigger event change */ + }); + } + }) + </script>'; + } + } } // Construct $out and $outarray diff --git a/htdocs/core/class/html.formcompany.class.php b/htdocs/core/class/html.formcompany.class.php index d32c0def5ab663458bda8e933eeb09fd07a1fb9e..e45fffff759c8c96af1f6487a90aa1d988590382 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 f21d7d2ff028f372e840301c8d4ac8d92f5c69d2..3966b29f874dc13af4bc765939886b82a6bcf643 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;