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 if (!is_array($helpbuttonargs)){
29 $helpbuttonargs=array($helpbuttonargs);
31 $helpbuttonargs=$helpbuttonargs;
33 //we do this to to return html instead of printing it
34 //without having to specify it in every call to make a button.
35 if ('helpbutton' == $function){
36 $defaultargs=array('', '', 'moodle', true, false, '', true);
37 $helpbuttonargs=$helpbuttonargs +
$defaultargs ;
39 $this->_helpbutton
=call_user_func_array($function, $helpbuttonargs);
42 * get html for help button
45 * @return string html for help button
47 function getHelpButton(){
48 return $this->_helpbutton
;
51 * Automatically generates and assigns an 'id' attribute for the element.
53 * Currently used to ensure that labels work on radio buttons and
54 * checkboxes. Per idea of Alexander Radivanovich.
55 * Overriden in moodleforms to remove qf_ prefix.
60 function _generateId()
64 if (!$this->getAttribute('id')) {
65 $this->updateAttributes(array('id' => 'id_'.substr(md5(microtime() . $idx++
), 0, 6)));
67 } // end func _generateId
69 * Called by HTML_QuickForm whenever form event is made on this element
71 * @param string $event Name of event
72 * @param mixed $arg event arguments
73 * @param object $caller calling object
78 function onQuickFormEvent($event, $arg, &$caller)
80 //fixes bug in quickforms which lets previous set value override submitted value if checkbox is not checked
81 // and no value is submitted
84 // constant values override both default and submitted ones
85 // default values are overriden by submitted
86 $value = $this->_findValue($caller->_constantValues
);
87 if (null === $value) {
88 // if no boxes were checked, then there is no value in the array
89 // yet we don't want to display default value in this case
90 if ($caller->isSubmitted()) {
91 $value = $this->_findValue($caller->_submitValues
);
94 $value = $this->_findValue($caller->_defaultValues
);
97 //fix here. setChecked should not be conditional
98 $this->setChecked($value);
101 parent
::onQuickFormEvent($event, $arg, $caller);
104 } // end func onQuickFormEvent
107 return '<span>' . parent
::toHtml() . '</span>';
111 * Returns the disabled field. Accessibility: the return "[ ]" from parent
112 * class is not acceptable for screenreader users, and we DO want a label.
115 function getFrozenHtml()
117 //$this->_generateId();
118 $output = '<input type="checkbox" disabled="disabled" id="'.$this->getAttribute('id').'" ';
119 if ($this->getChecked()) {
120 $output .= 'checked="checked" />'.$this->_getPersistantData();
125 } //end func getFrozenHtml