From da40fd32189ce3f3bdcfbdcbe6c0af9cea3a9e25 Mon Sep 17 00:00:00 2001 From: skodak Date: Sun, 10 May 2009 11:49:00 +0000 Subject: [PATCH] MDL-19139 selectgroups formslib element improvements - 1/ does not validate if optgroup array empty 2/ add optional $showchoose parameter which adds "Choose..." as first item of list with empty value; merged from MOODLE_19_STABLE --- lib/form/selectgroups.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/form/selectgroups.php b/lib/form/selectgroups.php index c226f5da6e..8cb0539cbd 100644 --- a/lib/form/selectgroups.php +++ b/lib/form/selectgroups.php @@ -34,6 +34,9 @@ class MoodleQuickForm_selectgroups extends HTML_QuickForm_element { // {{{ properties + /** add choose option */ + var $showchoose = false; + /** * Contains the select optgroups * @@ -69,12 +72,14 @@ class MoodleQuickForm_selectgroups extends HTML_QuickForm_element { * @param mixed An array whose keys are labels for optgroups and whose values are arrays similar to those passed * to the select element with keys that are values for options and values are strings for display. * @param mixed Either a typical HTML attribute string or an associative array + * @param bool add standard moodle "Choose..." option as first item * @since 1.0 * @access public * @return void */ - function MoodleQuickForm_selectgroups($elementName=null, $elementLabel=null, $optgrps=null, $attributes=null) + function MoodleQuickForm_selectgroups($elementName=null, $elementLabel=null, $optgrps=null, $attributes=null, $showchoose=false) { + $this->showchoose = $showchoose; HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel, $attributes); $this->_persistantFreeze = true; $this->_type = 'selectgroups'; @@ -407,7 +412,14 @@ class MoodleQuickForm_selectgroups extends HTML_QuickForm_element { $this->getLabel().''; } $strHtml .= '\n"; + if ($this->showchoose) { + $strHtml .= $tabs . "\t\t\n"; + } foreach ($this->_optGroups as $optGroup) { + if (empty($optGroup['options'])) { + //xhtml strict + continue; + } $strHtml .= $tabs . "\t_getAttrString($optGroup['attr'])) . '>'; foreach ($optGroup['options'] as $option){ if (is_array($this->_values) && in_array((string)$option['attr']['value'], $this->_values)) { -- 2.39.5