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;
18 function setHiddenLabel($hiddenLabel){
19 $this->_hiddenLabel
= $hiddenLabel;
22 if ($this->_hiddenLabel
){
24 return '<label class="accesshide" for="'.$this->getAttribute('id').'" >'.
25 $this->getLabel().'</label>'.parent
::toHtml();
27 return parent
::toHtml();
31 * Automatically generates and assigns an 'id' attribute for the element.
33 * Currently used to ensure that labels work on radio buttons and
34 * checkboxes. Per idea of Alexander Radivanovich.
35 * Overriden in moodleforms to remove qf_ prefix.
40 function _generateId()
44 if (!$this->getAttribute('id')) {
45 $this->updateAttributes(array('id' => 'id_'. substr(md5(microtime() . $idx++
), 0, 6)));
47 } // end func _generateId
49 * set html for help button
52 * @param array $help array of arguments to make a help button
53 * @param string $function function name to call to get html
55 function setHelpButton($helpbuttonargs, $function='helpbutton'){
56 if (!is_array($helpbuttonargs)){
57 $helpbuttonargs=array($helpbuttonargs);
59 $helpbuttonargs=$helpbuttonargs;
61 //we do this to to return html instead of printing it
62 //without having to specify it in every call to make a button.
63 if ('helpbutton' == $function){
64 $defaultargs=array('', '', 'moodle', true, false, '', true);
65 $helpbuttonargs=$helpbuttonargs +
$defaultargs ;
67 $this->_helpbutton
=call_user_func_array($function, $helpbuttonargs);
70 * get html for help button
73 * @return string html for help button
75 function getHelpButton(){
76 return $this->_helpbutton
;
79 * Removes an OPTION from the SELECT
81 * @param string $value Value for the OPTION to remove
86 function removeOption($value)
88 $key=array_search($value, $this->_values
);
89 if ($key!==FALSE and $key!==null) {
90 unset($this->_values
[$key]);
92 foreach ($this->_options
as $key=>$option){
93 if ($option['attr']['value']==$value){
94 unset($this->_options
[$key]);
98 } // end func removeOption
100 * Removes all OPTIONs from the SELECT
102 * @param string $value Value for the OPTION to remove
107 function removeOptions()
109 $this->_options
= array();
110 } // end func removeOption
112 * Slightly different container template when frozen. Don't want to use a label tag
113 * with a for attribute in that case for the element label but instead use a div.
114 * Templates are defined in renderer constructor.
118 function getElementTemplateType(){
119 if ($this->_flagFrozen
){