Fix: Missing event management into select when combo not selected
This commit is contained in:
parent
d164b2d0e1
commit
6bac744709
@ -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'));
|
$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
|
//For external user force the company to user company
|
||||||
if (!empty($user->societe_id)) {
|
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 {
|
} else {
|
||||||
print $form->select_company('','socid','',1,1,0,$events);
|
print $form->select_thirdparty_list('','socid','',1,1,0,$events);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -746,7 +746,7 @@ class Form
|
|||||||
* @param int $showempty Add an empty field
|
* @param int $showempty Add an empty field
|
||||||
* @param int $showtype Show third party type in combolist (customer, prospect or supplier)
|
* @param int $showtype Show third party type in combolist (customer, prospect or supplier)
|
||||||
* @param int $forcecombo Force to use combo box
|
* @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
|
* @param int $limit Maximum number of elements
|
||||||
* @return string HTML string with
|
* @return string HTML string with
|
||||||
* @deprecated Use select_thirdparty instead
|
* @deprecated Use select_thirdparty instead
|
||||||
@ -816,11 +816,68 @@ class Form
|
|||||||
$resql=$this->db->query($sql);
|
$resql=$this->db->query($sql);
|
||||||
if ($resql)
|
if ($resql)
|
||||||
{
|
{
|
||||||
if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->COMPANY_USE_SEARCH_TO_SELECT) && ! $forcecombo)
|
if (! empty($conf->use_javascript_ajax))
|
||||||
|
{
|
||||||
|
if (! empty($conf->global->COMPANY_USE_SEARCH_TO_SELECT) && ! $forcecombo)
|
||||||
{
|
{
|
||||||
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
|
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
|
||||||
$out.= ajax_combobox($htmlname, $events, $conf->global->COMPANY_USE_SEARCH_TO_SELECT);
|
$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
|
// Construct $out and $outarray
|
||||||
$out.= '<select id="'.$htmlname.'" class="flat" name="'.$htmlname.'">'."\n";
|
$out.= '<select id="'.$htmlname.'" class="flat" name="'.$htmlname.'">'."\n";
|
||||||
|
|||||||
@ -547,7 +547,7 @@ class FormCompany
|
|||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
if ($resql)
|
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
|
// Use Ajax search
|
||||||
$minLength = (is_numeric($conf->global->COMPANY_USE_SEARCH_TO_SELECT)?$conf->global->COMPANY_USE_SEARCH_TO_SELECT:2);
|
$minLength = (is_numeric($conf->global->COMPANY_USE_SEARCH_TO_SELECT)?$conf->global->COMPANY_USE_SEARCH_TO_SELECT:2);
|
||||||
|
|||||||
@ -345,13 +345,13 @@ function ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0)
|
|||||||
var obj = '.json_encode($events).';
|
var obj = '.json_encode($events).';
|
||||||
$.each(obj, function(key,values) {
|
$.each(obj, function(key,values) {
|
||||||
if (values.method.length) {
|
if (values.method.length) {
|
||||||
runJsCodeForEvent(values);
|
runJsCodeForEvent'.$htmlname.'(values);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function runJsCodeForEvent(obj) {
|
function runJsCodeForEvent'.$htmlname.'(obj) {
|
||||||
var id = $("#'.$htmlname.'").val();
|
var id = $("#'.$htmlname.'").val();
|
||||||
var method = obj.method;
|
var method = obj.method;
|
||||||
var url = obj.url;
|
var url = obj.url;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user