From 86b6811e9770adfacbe50bddf7190868563012f0 Mon Sep 17 00:00:00 2001 From: stronk7 Date: Sat, 17 Jan 2009 18:09:38 +0000 Subject: [PATCH] MDL-17331 choose_from_menu() - backport listbox, multiple and class params --- lib/weblib.php | 43 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/lib/weblib.php b/lib/weblib.php index 55c7ca1f06d..d822a068187 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -848,7 +848,6 @@ function close_window($delay=0) { die; } - /** * Given an array of values, output the HTML for a select element with those options. * Normally, you only need to use the first few parameters. @@ -867,9 +866,17 @@ function close_window($delay=0) { * @param int $tabindex if give, sets the tabindex attribute on the <select> element. Default none. * @param string $id value to use for the id attribute of the <select> element. If none is given, * then a suitable one is constructed. + * @param mixed $listbox if false, display as a dropdown menu. If true, display as a list box. + * By default, the list box will have a number of rows equal to min(10, count($options)), but if + * $listbox is an integer, that number is used for size instead. + * @param boolean $multiple if true, enable multiple selections, else only 1 item can be selected. Used + * when $listbox display is enabled + * @param string $class value to use for the class attribute of the <select> element. If none is given, + * then a suitable one is constructed. */ function choose_from_menu ($options, $name, $selected='', $nothing='choose', $script='', - $nothingvalue='0', $return=false, $disabled=false, $tabindex=0, $id='') { + $nothingvalue='0', $return=false, $disabled=false, $tabindex=0, + $id='', $listbox=false, $multiple=false, $class='') { if ($nothing == 'choose') { $nothing = get_string('choose') .'...'; @@ -886,12 +893,36 @@ function choose_from_menu ($options, $name, $selected='', $nothing='choose', $sc if ($id ==='') { $id = 'menu'.$name; - // name may contaion [], which would make an invalid id. e.g. numeric question type editing form, assignment quickgrading + // name may contaion [], which would make an invalid id. e.g. numeric question type editing form, assignment quickgrading $id = str_replace('[', '', $id); $id = str_replace(']', '', $id); } - $output = '' . "\n"; if ($nothing) { $output .= '