2 require_once('HTML/QuickForm/checkbox.php');
5 * HTML class for a checkbox type element
10 class MoodleQuickForm_checkbox
extends HTML_QuickForm_checkbox
{
12 * html for help button, if empty then no help
17 function MoodleQuickForm_checkbox($elementName=null, $elementLabel=null, $text='', $attributes=null) {
18 parent
::HTML_QuickForm_checkbox($elementName, $elementLabel, $text, $attributes);
21 * set html for help button
24 * @param array $help array of arguments to make a help button
25 * @param string $function function name to call to get html
27 function setHelpButton($helpbuttonargs, $function='helpbutton'){
28 debugging('component setHelpButton() is not used any more, please use $mform->setHelpButton() instead');
31 * get html for help button
34 * @return string html for help button
36 function getHelpButton(){
37 return $this->_helpbutton
;
40 * Automatically generates and assigns an 'id' attribute for the element.
42 * Currently used to ensure that labels work on radio buttons and
43 * checkboxes. Per idea of Alexander Radivanovich.
44 * Overriden in moodleforms to remove qf_ prefix.
49 function _generateId()
53 if (!$this->getAttribute('id')) {
54 $this->updateAttributes(array('id' => 'id_'.substr(md5(microtime() . $idx++
), 0, 6)));
56 } // end func _generateId
58 * Called by HTML_QuickForm whenever form event is made on this element
60 * @param string $event Name of event
61 * @param mixed $arg event arguments
62 * @param object $caller calling object
67 function onQuickFormEvent($event, $arg, &$caller)
69 //fixes bug in quickforms which lets previous set value override submitted value if checkbox is not checked
70 // and no value is submitted
73 // constant values override both default and submitted ones
74 // default values are overriden by submitted
75 $value = $this->_findValue($caller->_constantValues
);
76 if (null === $value) {
77 // if no boxes were checked, then there is no value in the array
78 // yet we don't want to display default value in this case
79 if ($caller->isSubmitted()) {
80 $value = $this->_findValue($caller->_submitValues
);
83 $value = $this->_findValue($caller->_defaultValues
);
86 //fix here. setChecked should not be conditional
87 $this->setChecked($value);
90 parent
::onQuickFormEvent($event, $arg, $caller);
93 } // end func onQuickFormEvent
96 return '<span>' . parent
::toHtml() . '</span>';
100 * Returns the disabled field. Accessibility: the return "[ ]" from parent
101 * class is not acceptable for screenreader users, and we DO want a label.
104 function getFrozenHtml()
106 //$this->_generateId();
107 $output = '<input type="checkbox" disabled="disabled" id="'.$this->getAttribute('id').'" ';
108 if ($this->getChecked()) {
109 $output .= 'checked="checked" />'.$this->_getPersistantData();
114 } //end func getFrozenHtml