Enhance prototype for select
This commit is contained in:
parent
39b932d37e
commit
5bac040a9a
@ -4347,7 +4347,8 @@ class Form
|
|||||||
$out.='<!-- JS CODE TO ENABLE '.$tmpplugin.' for id '.$htmlname.' -->
|
$out.='<!-- JS CODE TO ENABLE '.$tmpplugin.' for id '.$htmlname.' -->
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
$(\'#'.$htmlname.'\').'.$tmpplugin.'({
|
$(\''.(preg_match('/^\./',$htmlname)?$htmlname:'#'.$htmlname).'\').'.$tmpplugin.'({
|
||||||
|
dir: \'ltr\',
|
||||||
width: \'off\',
|
width: \'off\',
|
||||||
minimumInputLength: 0
|
minimumInputLength: 0
|
||||||
});
|
});
|
||||||
@ -4355,7 +4356,7 @@ class Form
|
|||||||
</script>';
|
</script>';
|
||||||
}
|
}
|
||||||
|
|
||||||
$out.='<select id="'.$htmlname.'" '.($disabled?'disabled ':'').'class="flat'.($morecss?' '.$morecss:'').'" name="'.$htmlname.'" '.($moreparam?$moreparam:'').'>';
|
$out.='<select id="'.preg_replace('/^\./','',$htmlname).'" '.($disabled?'disabled="disabled" ':'').'class="flat '.(preg_replace('/^\./','',$htmlname)).($morecss?' '.$morecss:'').'" name="'.preg_replace('/^\./','',$htmlname).'" '.($moreparam?$moreparam:'').'>';
|
||||||
|
|
||||||
if ($show_empty)
|
if ($show_empty)
|
||||||
{
|
{
|
||||||
@ -4400,6 +4401,79 @@ class Form
|
|||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a HTML select string, built from an array of key+value.
|
||||||
|
* Note: Do not use returned string into a langs->trans function, content may be entity encoded twice.
|
||||||
|
*
|
||||||
|
* @param string $url Url
|
||||||
|
* @param string $htmlname Name of html select area
|
||||||
|
* @param array $array Array with key+value
|
||||||
|
* @param string $id Preselected key
|
||||||
|
* @param int $show_empty 0 no empty value allowed, 1 to add an empty value into list (value is '' or ' ').
|
||||||
|
* @param int $key_in_label 1 pour afficher la key dans la valeur "[key] value"
|
||||||
|
* @param int $value_as_key 1 to use value as key
|
||||||
|
* @param string $moreparam Add more parameters onto the select tag
|
||||||
|
* @param int $translate Translate and encode value
|
||||||
|
* @param int $maxlen Length maximum for labels
|
||||||
|
* @param int $disabled Html select box is disabled
|
||||||
|
* @param int $sort 'ASC' or 'DESC' = Sort on label, '' or 'NONE' = Do not sort
|
||||||
|
* @param string $morecss Add more class to css styles
|
||||||
|
* @param int $addjscombo Add js combo
|
||||||
|
* @return string HTML select string.
|
||||||
|
*/
|
||||||
|
static function selectArrayAjax($url, $htmlname, $array, $id='', $show_empty=0, $key_in_label=0, $value_as_key=0, $moreparam='', $translate=0, $maxlen=0, $disabled=0, $sort='', $morecss='', $addjscombo=0)
|
||||||
|
{
|
||||||
|
$out = '';
|
||||||
|
|
||||||
|
// Add code for jquery to use multiselect
|
||||||
|
if ($addjscombo && empty($conf->dol_use_jmobile))
|
||||||
|
{
|
||||||
|
$tmpplugin='select2';
|
||||||
|
$out.='<!-- JS CODE TO ENABLE '.$tmpplugin.' for id '.$htmlname.' -->
|
||||||
|
<script type="text/javascript">
|
||||||
|
$(document).ready(function () {
|
||||||
|
$(".'.$htmlname.'").select2({
|
||||||
|
ajax: {
|
||||||
|
dir: "ltr",
|
||||||
|
url: "'.$url.'",
|
||||||
|
dataType: \'json\',
|
||||||
|
delay: 250,
|
||||||
|
data: function (params) {
|
||||||
|
return {
|
||||||
|
q: params.term, // search term
|
||||||
|
page: params.page
|
||||||
|
};
|
||||||
|
},
|
||||||
|
processResults: function (data, page) {
|
||||||
|
// parse the results into the format expected by Select2.
|
||||||
|
// since we are using custom formatting functions we do not need to
|
||||||
|
// alter the remote JSON data
|
||||||
|
return {
|
||||||
|
results: data.items
|
||||||
|
};
|
||||||
|
},
|
||||||
|
cache: true
|
||||||
|
},
|
||||||
|
escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
|
||||||
|
minimumInputLength: 0,
|
||||||
|
//templateResult: formatRepo, // omitted for brevity, see the source of this page
|
||||||
|
//templateSelection: formatRepoSelection // omitted for brevity, see the source of this page
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// TODO get values from ajax page to use a standard already completed array
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$out.=self::selectarray('.'.$htmlname, $array, $id, $show_empty, $key_in_label, $value_as_key, '', $translate, $maxlen, $disabled, $sort, '', 0);
|
||||||
|
|
||||||
|
return $out;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show a multiselect form from an array.
|
* Show a multiselect form from an array.
|
||||||
*
|
*
|
||||||
@ -4450,6 +4524,7 @@ class Form
|
|||||||
print ' };
|
print ' };
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
$(\'#'.$htmlname.'\').'.$tmpplugin.'({
|
$(\'#'.$htmlname.'\').'.$tmpplugin.'({
|
||||||
|
dir: \'ltr\',
|
||||||
// Specify format function for dropdown item
|
// Specify format function for dropdown item
|
||||||
formatResult: formatResult,
|
formatResult: formatResult,
|
||||||
templateResult: formatResult, /* For 4.0 */
|
templateResult: formatResult, /* For 4.0 */
|
||||||
@ -4493,6 +4568,7 @@ class Form
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render list of categories linked to object with id $id and type $type
|
* Render list of categories linked to object with id $id and type $type
|
||||||
*
|
*
|
||||||
|
|||||||
@ -61,8 +61,9 @@ else
|
|||||||
|
|
||||||
<h1>
|
<h1>
|
||||||
This page is a sample of page using tables. It is designed to make test with<br>
|
This page is a sample of page using tables. It is designed to make test with<br>
|
||||||
- css (add parameter &theme=newthem to test another theme or edit css of current theme)<br>
|
- css (add parameter &theme=newtheme to test another theme or edit css of current theme)<br>
|
||||||
- jmobile (add parameter dol_use_jmobile=1&dol_optimize_smallscreen=1 to enable view with jmobile)<br>
|
- jmobile (add parameter dol_use_jmobile=1&dol_optimize_smallscreen=1 to enable view with jmobile)<br>
|
||||||
|
- no javascript / usage for bind people (add parameter nojs=1 to force disable javascript)<br>
|
||||||
- dataTables<br>
|
- dataTables<br>
|
||||||
- tablednd<br>
|
- tablednd<br>
|
||||||
</h1>
|
</h1>
|
||||||
|
|||||||
@ -16,8 +16,9 @@ llxHeader();
|
|||||||
|
|
||||||
<h1>
|
<h1>
|
||||||
This page is a sample of page using Dolibarr HTML widget methods. It is designed to make test with<br>
|
This page is a sample of page using Dolibarr HTML widget methods. It is designed to make test with<br>
|
||||||
- css (edit page to change to test another css)<br>
|
- css (add parameter &theme=newtheme to test another theme or edit css of current theme)<br>
|
||||||
- jmobile (add parameter dol_use_jmobile=1 to enable view with jmobile)<br>
|
- jmobile (add parameter dol_use_jmobile=1&dol_optimize_smallscreen=1 to enable view with jmobile)<br>
|
||||||
|
- no javascript / usage for bind people (add parameter nojs=1 to force disable javascript)<br>
|
||||||
</h1>
|
</h1>
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
@ -44,41 +45,52 @@ print '<br><br>'."\n";
|
|||||||
print "Test 3: We must have here 1970-01-01 00:00:00 selected (fields are mandatory)<br>\n";
|
print "Test 3: We must have here 1970-01-01 00:00:00 selected (fields are mandatory)<br>\n";
|
||||||
$form->select_date(dol_get_first_day(1970,1,false), 'test3', 1, 1, 0);
|
$form->select_date(dol_get_first_day(1970,1,false), 'test3', 1, 1, 0);
|
||||||
|
|
||||||
print '<br><br>'."\n";
|
/*print '<br><br>'."\n";
|
||||||
|
|
||||||
// Test4a: form->select_product
|
print "Test 4c: a select with ajax refresh<br>\n";
|
||||||
print "Test 4: Select product - ";
|
//$array=array(0=>'',1=>'Search into xxx',2=>'Search into yyy',3=>'Search into zzz');
|
||||||
$form->select_produits(0,'producttest');
|
$array=array();
|
||||||
|
$selected=-1;
|
||||||
|
print $form->selectArrayAjax(DOL_URL_ROOT.'/core/ajax/selecsearchbox.php', 'testselectc', $array, $selected, 1, 0, 0, 'style="min-width: 250px;"', 0, 0, 0, '', '', 1);
|
||||||
|
*/
|
||||||
|
|
||||||
print '<br><br>'."\n";
|
print '<br><br>'."\n";
|
||||||
|
|
||||||
// Test4b: form->selectarray
|
// Test4: a select
|
||||||
print "Test 4: Select array - ";
|
print "Test 4a: a select<br>\n";
|
||||||
|
$array=array(1=>'Value 1',2=>'Value 2',3=>'Value 3 ith a very long text. aze eazeae e ae aeae a e a ea ea ea e a e aea e ae aeaeaeaze.');
|
||||||
|
$selected=3;
|
||||||
|
print $form->selectarray('testselecta', $array, $selected, 1, 0, 0, 'style="min-width: 250px;"', 0, 0, 0, '', '', 1);
|
||||||
|
print '<br><br>';
|
||||||
|
print "Test 4b: a select<br>\n";
|
||||||
|
$array=array(1=>'Value 1',2=>'Value 2',3=>'Value 3');
|
||||||
|
$selected=3;
|
||||||
|
print $form->selectarray('testselectb', $array, $selected, 1, 0, 0, 'style="min-width: 250px;"', 0, 0, 0, '', '', 1);
|
||||||
|
print '<br><br>'."\n";
|
||||||
|
print "Test 4c: Select array with no js forced<br>\n";
|
||||||
$array=array(1=>'Value 1',2=>'Value 2',3=>'Value 3');
|
$array=array(1=>'Value 1',2=>'Value 2',3=>'Value 3');
|
||||||
$arrayselected=array(1,3);
|
|
||||||
print $form->selectarray('selectarray',$array);
|
print $form->selectarray('selectarray',$array);
|
||||||
|
|
||||||
print '<br><br>'."\n";
|
print '<br><br>'."\n";
|
||||||
|
|
||||||
|
// Test4d: form->select_thirdparty
|
||||||
|
print "Test 4d: Select thirdparty<br>\n";
|
||||||
|
print $form->select_thirdparty(0,'thirdpartytest');
|
||||||
|
|
||||||
|
print '<br><br>'."\n";
|
||||||
|
|
||||||
|
// Test4e: form->select_product
|
||||||
|
print "Test 4e: Select product (using ajax)<br>\n";
|
||||||
|
$form->select_produits(0,'producttest');
|
||||||
|
|
||||||
|
print '<br><br>'."\n";
|
||||||
|
|
||||||
// Test5: a multiselect
|
// Test5: a multiselect
|
||||||
print "Test 5: a multiselect<br>\n";
|
print "Test 5: a multiselect<br>\n";
|
||||||
$array=array(1=>'Value 1',2=>'Value 2',3=>'Value 3');
|
$array=array(1=>'Value 1',2=>'Value 2',3=>'Value 3');
|
||||||
$arrayselected=array(1,3);
|
$arrayselected=array(1,3);
|
||||||
print $form->multiselectarray('testmulti', $array, $arrayselected, '', 0, '', 0, 250);
|
print $form->multiselectarray('testmulti', $array, $arrayselected, '', 0, '', 0, 250);
|
||||||
|
|
||||||
print '<br><br>'."\n";
|
|
||||||
|
|
||||||
// Test6: a select
|
|
||||||
print "Test 6a: a select<br>\n";
|
|
||||||
$array=array(1=>'Value 1',2=>'Value 2',3=>'Value 3 ith a very long text. aze eazeae e ae aeae a e a ea ea ea e a e aea e ae aeaeaeaze.');
|
|
||||||
$selected=3;
|
|
||||||
print $form->selectarray('testselecta', $array, $selected, 1, 0, 0, 'style="min-width: 250px;"', 0, 0, 0, '', '', 1);
|
|
||||||
print '<br><br>';
|
|
||||||
print "Test 6b: a select<br>\n";
|
|
||||||
$array=array(1=>'Value 1',2=>'Value 2',3=>'Value 3');
|
|
||||||
$selected=3;
|
|
||||||
print $form->selectarray('testselectb', $array, $selected, 1, 0, 0, 'style="min-width: 250px;"', 0, 0, 0, '', '', 1);
|
|
||||||
|
|
||||||
|
|
||||||
llxFooter();
|
llxFooter();
|
||||||
$db->close();
|
$db->close();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user