mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 04:30:15 +01:00
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
This commit is contained in:
parent
adf8cf19bc
commit
da40fd3218
@ -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().'</label>';
|
||||
}
|
||||
$strHtml .= '<select' . $attrString . ">\n";
|
||||
if ($this->showchoose) {
|
||||
$strHtml .= $tabs . "\t\t<option value=\"\">" . get_string('choose') . "...</option>\n";
|
||||
}
|
||||
foreach ($this->_optGroups as $optGroup) {
|
||||
if (empty($optGroup['options'])) {
|
||||
//xhtml strict
|
||||
continue;
|
||||
}
|
||||
$strHtml .= $tabs . "\t<optgroup" . ($this->_getAttrString($optGroup['attr'])) . '>';
|
||||
foreach ($optGroup['options'] as $option){
|
||||
if (is_array($this->_values) && in_array((string)$option['attr']['value'], $this->_values)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user