Close #18253 by manual merge
This commit is contained in:
parent
534f1868f5
commit
9f13f17e36
@ -1346,6 +1346,8 @@ class Form
|
|||||||
$out .= img_picto($langs->trans("Search"), 'search');
|
$out .= img_picto($langs->trans("Search"), 'search');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$out .= ajax_event($htmlname, $events);
|
||||||
|
|
||||||
$out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/societe/ajax/company.php', $urloption, $conf->global->COMPANY_USE_SEARCH_TO_SELECT, 0, $ajaxoptions);
|
$out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/societe/ajax/company.php', $urloption, $conf->global->COMPANY_USE_SEARCH_TO_SELECT, 0, $ajaxoptions);
|
||||||
} else {
|
} else {
|
||||||
// Immediate load of all database
|
// Immediate load of all database
|
||||||
|
|||||||
@ -526,17 +526,39 @@ function ajax_combobox($htmlname, $events = array(), $minLengthToAutocomplete =
|
|||||||
}
|
}
|
||||||
$msg .= ';'."\n";
|
$msg .= ';'."\n";
|
||||||
|
|
||||||
|
$msg .= '});'."\n";
|
||||||
|
$msg .= "</script>\n";
|
||||||
|
|
||||||
|
$msg .= ajax_event($htmlname, $events);
|
||||||
|
|
||||||
|
return $msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add event management script.
|
||||||
|
*
|
||||||
|
* @param string $htmlname Name of html select field ('myid' or '.myclass')
|
||||||
|
* @param array $events Add some Ajax events option on change of $htmlname component to call ajax to autofill a HTML element (select#htmlname and #inputautocompletehtmlname)
|
||||||
|
* Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled')))
|
||||||
|
* @return string Return JS string to manage event
|
||||||
|
*/
|
||||||
|
function ajax_event($htmlname, $events)
|
||||||
|
{
|
||||||
|
$out = '';
|
||||||
|
|
||||||
if (is_array($events) && count($events)) { // If an array of js events to do were provided.
|
if (is_array($events) && count($events)) { // If an array of js events to do were provided.
|
||||||
$msg .= '
|
$out = '<!-- JS code to manage event for id = ' . $htmlname . ' -->
|
||||||
|
<script>
|
||||||
|
$(document).ready(function () {
|
||||||
jQuery("#'.$htmlname.'").change(function () {
|
jQuery("#'.$htmlname.'").change(function () {
|
||||||
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'.$htmlname.'(values);
|
runJsCodeForEvent'.$htmlname.'(values);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function runJsCodeForEvent'.$htmlname.'(obj) {
|
function runJsCodeForEvent'.$htmlname.'(obj) {
|
||||||
var id = $("#'.$htmlname.'").val();
|
var id = $("#'.$htmlname.'").val();
|
||||||
var method = obj.method;
|
var method = obj.method;
|
||||||
@ -575,15 +597,15 @@ function ajax_combobox($htmlname, $events = array(), $minLengthToAutocomplete =
|
|||||||
$("select#" + htmlname).change(); /* Trigger event change */
|
$("select#" + htmlname).change(); /* Trigger event change */
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}';
|
}
|
||||||
|
});
|
||||||
|
</script>';
|
||||||
}
|
}
|
||||||
|
|
||||||
$msg .= '});'."\n";
|
return $out;
|
||||||
$msg .= "</script>\n";
|
|
||||||
|
|
||||||
return $msg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* On/off button for constant
|
* On/off button for constant
|
||||||
*
|
*
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user