2
0
forked from Wavyzz/dolibarr

New: Selection of project use the new select2 component.

This commit is contained in:
Laurent Destailleur
2015-01-30 19:57:38 +01:00
parent 291340a39f
commit 275e198041
13 changed files with 46 additions and 34 deletions

View File

@@ -314,25 +314,28 @@ function ajax_dialog($title,$message,$w=350,$h=150)
* @param string $htmlname Name of html select field
* @param array $events More events option. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled')))
* @param int $minLengthToAutocomplete Minimum length of input string to start autocomplete
* @param int $forcefocus Force focus on field
* @return string Return html string to convert a select field into a combo
*/
function ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0)
function ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0)
{
global $conf;
//if (! empty($conf->browser->phone)) return ''; // combobox disabled for smartphones (does not works)
//if (! empty($conf->dol_use_jmobile)) return ''; // select2 works with jmobile
if (! empty($conf->global->MAIN_DISABLE_AJAX_COMBOX)) return '';
if (empty($conf->use_javascript_ajax)) return '';
if (empty($conf->use_javascript_ajax)) return '';
if (empty($minLengthToAutocomplete)) $minLengthToAutocomplete=0;
$msg = '<script type="text/javascript">
$(document).ready(function() {
$(\'#'.$htmlname.'\').select2({
width: \'resolve\',
minimumInputLength: '.$minLengthToAutocomplete.',
});';
})';
if ($forcefocus) $msg.= '.select2(\'focus\')';
$msg.= ';';
if (count($event))
{
@@ -345,7 +348,7 @@ function ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0)
}
});
});
function runJsCodeForEvent'.$htmlname.'(obj) {
var id = $("#'.$htmlname.'").val();
var method = obj.method;
@@ -383,7 +386,7 @@ function ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0)
);
}';
}
$msg.= '});'."\n";
$msg.= "</script>\n";