From 5bac040a9ae2431dd08e09492899801988be7cce Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 10 May 2015 21:21:29 +0200 Subject: [PATCH] Enhance prototype for select --- htdocs/core/class/html.form.class.php | 80 ++++++++++++++++++++++++++- htdocs/public/test/test_arrays.php | 3 +- htdocs/public/test/test_forms.php | 56 +++++++++++-------- 3 files changed, 114 insertions(+), 25 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 1e05a3b6c3d..150ca48e477 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -4347,7 +4347,8 @@ class Form $out.=' '; } - $out.=''; if ($show_empty) { @@ -4400,6 +4401,79 @@ class Form 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.=' + '; + } + 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. * @@ -4450,6 +4524,7 @@ class Form print ' }; $(document).ready(function () { $(\'#'.$htmlname.'\').'.$tmpplugin.'({ + dir: \'ltr\', // Specify format function for dropdown item formatResult: formatResult, templateResult: formatResult, /* For 4.0 */ @@ -4493,6 +4568,7 @@ class Form } + /** * Render list of categories linked to object with id $id and type $type * diff --git a/htdocs/public/test/test_arrays.php b/htdocs/public/test/test_arrays.php index e08eb5715c4..c2be96b4468 100644 --- a/htdocs/public/test/test_arrays.php +++ b/htdocs/public/test/test_arrays.php @@ -61,8 +61,9 @@ else

This page is a sample of page using tables. It is designed to make test with
-- css (add parameter &theme=newthem to test another theme or edit css of current theme)
+- css (add parameter &theme=newtheme to test another theme or edit css of current theme)
- jmobile (add parameter dol_use_jmobile=1&dol_optimize_smallscreen=1 to enable view with jmobile)
+- no javascript / usage for bind people (add parameter nojs=1 to force disable javascript)
- dataTables
- tablednd

diff --git a/htdocs/public/test/test_forms.php b/htdocs/public/test/test_forms.php index 86db08fe148..c0c81882fe2 100644 --- a/htdocs/public/test/test_forms.php +++ b/htdocs/public/test/test_forms.php @@ -16,8 +16,9 @@ llxHeader();

This page is a sample of page using Dolibarr HTML widget methods. It is designed to make test with
-- css (edit page to change to test another css)
-- jmobile (add parameter dol_use_jmobile=1 to enable view with jmobile)
+- css (add parameter &theme=newtheme to test another theme or edit css of current theme)
+- jmobile (add parameter dol_use_jmobile=1&dol_optimize_smallscreen=1 to enable view with jmobile)
+- no javascript / usage for bind people (add parameter nojs=1 to force disable javascript)


@@ -44,41 +45,52 @@ print '

'."\n"; print "Test 3: We must have here 1970-01-01 00:00:00 selected (fields are mandatory)
\n"; $form->select_date(dol_get_first_day(1970,1,false), 'test3', 1, 1, 0); -print '

'."\n"; +/*print '

'."\n"; -// Test4a: form->select_product -print "Test 4: Select product - "; -$form->select_produits(0,'producttest'); +print "Test 4c: a select with ajax refresh
\n"; +//$array=array(0=>'',1=>'Search into xxx',2=>'Search into yyy',3=>'Search into zzz'); +$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 '

'."\n"; -// Test4b: form->selectarray -print "Test 4: Select array - "; +// Test4: a select +print "Test 4a: a select
\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 '

'; +print "Test 4b: a select
\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 '

'."\n"; +print "Test 4c: Select array with no js forced
\n"; $array=array(1=>'Value 1',2=>'Value 2',3=>'Value 3'); -$arrayselected=array(1,3); print $form->selectarray('selectarray',$array); print '

'."\n"; +// Test4d: form->select_thirdparty +print "Test 4d: Select thirdparty
\n"; +print $form->select_thirdparty(0,'thirdpartytest'); + +print '

'."\n"; + +// Test4e: form->select_product +print "Test 4e: Select product (using ajax)
\n"; +$form->select_produits(0,'producttest'); + +print '

'."\n"; + // Test5: a multiselect print "Test 5: a multiselect
\n"; $array=array(1=>'Value 1',2=>'Value 2',3=>'Value 3'); $arrayselected=array(1,3); print $form->multiselectarray('testmulti', $array, $arrayselected, '', 0, '', 0, 250); -print '

'."\n"; - -// Test6: a select -print "Test 6a: a select
\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 '

'; -print "Test 6b: a select
\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(); $db->close();