2 require_once('HTML/QuickForm/select.php');
5 * HTML class for a select type element
10 class MoodleQuickForm_select
extends HTML_QuickForm_select
{
12 * html for help button, if empty then no help
17 var $_hiddenLabel=false;
19 function MoodleQuickForm_select($elementName=null, $elementLabel=null, $options=null, $attributes=null) {
20 parent
::HTML_QuickForm_select($elementName, $elementLabel, $options, $attributes);
22 function setHiddenLabel($hiddenLabel){
23 $this->_hiddenLabel
= $hiddenLabel;
26 if ($this->_hiddenLabel
){
28 return '<label class="accesshide" for="'.$this->getAttribute('id').'" >'.
29 $this->getLabel().'</label>'.parent
::toHtml();
31 return parent
::toHtml();
35 * Automatically generates and assigns an 'id' attribute for the element.
37 * Currently used to ensure that labels work on radio buttons and
38 * checkboxes. Per idea of Alexander Radivanovich.
39 * Overriden in moodleforms to remove qf_ prefix.
44 function _generateId()
48 if (!$this->getAttribute('id')) {
49 $this->updateAttributes(array('id' => 'id_'. substr(md5(microtime() . $idx++
), 0, 6)));
51 } // end func _generateId
53 * set html for help button
56 * @param array $help array of arguments to make a help button
57 * @param string $function function name to call to get html
59 function setHelpButton($helpbuttonargs, $function='helpbutton'){
60 if (!is_array($helpbuttonargs)){
61 $helpbuttonargs=array($helpbuttonargs);
63 $helpbuttonargs=$helpbuttonargs;
65 //we do this to to return html instead of printing it
66 //without having to specify it in every call to make a button.
67 if ('helpbutton' == $function){
68 $defaultargs=array('', '', 'moodle', true, false, '', true);
69 $helpbuttonargs=$helpbuttonargs +
$defaultargs ;
71 $this->_helpbutton
=call_user_func_array($function, $helpbuttonargs);
74 * get html for help button
77 * @return string html for help button
79 function getHelpButton(){
80 return $this->_helpbutton
;
83 * Removes an OPTION from the SELECT
85 * @param string $value Value for the OPTION to remove
90 function removeOption($value)
92 $key=array_search($value, $this->_values
);
93 if ($key!==FALSE and $key!==null) {
94 unset($this->_values
[$key]);
96 foreach ($this->_options
as $key=>$option){
97 if ($option['attr']['value']==$value){
98 unset($this->_options
[$key]);
99 // we must reindex the options because the ugly code in quickforms' select.php expects that keys are 0,1,2,3... !?!?
100 $this->_options
= array_merge($this->_options
);
104 } // end func removeOption
106 * Removes all OPTIONs from the SELECT
108 * @param string $value Value for the OPTION to remove
113 function removeOptions()
115 $this->_options
= array();
116 } // end func removeOption
118 * Slightly different container template when frozen. Don't want to use a label tag
119 * with a for attribute in that case for the element label but instead use a div.
120 * Templates are defined in renderer constructor.
124 function getElementTemplateType(){
125 if ($this->_flagFrozen
){