if($this->_options['optional']) {
$this->_elements[] =& MoodleQuickForm::createElement('checkbox', 'off', null, get_string('disable'), $this->getAttributes(), true);
}
+ foreach ($this->_elements as $element){
+ if (method_exists($element, 'setHiddenLabel')){
+ $element->setHiddenLabel(true);
+ }
+ }
}
if($this->_options['optional']) {
$this->_elements[] =& MoodleQuickForm::createElement('checkbox', 'off', null, get_string('disable'), $this->getAttributes(), true);
}
+ foreach ($this->_elements as $element){
+ if (method_exists($element, 'setHiddenLabel')){
+ $element->setHiddenLabel(true);
+ }
+ }
}
function getElementTemplateType(){
return $this->_elementTemplateType;
}
+ function setElements($elements){
+ parent::setElements($elements);
+ foreach ($this->_elements as $element){
+ if (method_exists($element, 'setHiddenLabel')){
+ $element->setHiddenLabel(true);
+ }
+ }
+ }
}
?>
\ No newline at end of file
* @var string
*/
var $_helpbutton='';
+ var $_hiddenLabel=false;
+ function setHiddenLabel($hiddenLabel){
+ $this->_hiddenLabel = $hiddenLabel;
+ }
+ function toHtml(){
+ $this->_generateId();
+ if ($this->_hiddenLabel){
+ return '<label class="accesshide" for="'.$this->getAttribute('id').'" >'.
+ $this->getLabel().'</label>'.parent::toHtml();
+ } else {
+ return parent::toHtml();
+ }
+ }
+ /**
+ * Automatically generates and assigns an 'id' attribute for the element.
+ *
+ * Currently used to ensure that labels work on radio buttons and
+ * checkboxes. Per idea of Alexander Radivanovich.
+ * Overriden in moodleforms to remove qf_ prefix.
+ *
+ * @access private
+ * @return void
+ */
+ function _generateId()
+ {
+ static $idx = 1;
+
+ if (!$this->getAttribute('id')) {
+ $this->updateAttributes(array('id' => 'id_'. substr(md5(microtime() . $idx++), 0, 6)));
+ }
+ } // end func _generateId
/**
* set html for help button
*
}
}
} // end func removeOption
+
}
?>
\ No newline at end of file
* @var string
*/
var $_helpbutton='';
+ var $_hiddenLabel=false;
+ function setHiddenLabel($hiddenLabel){
+ $this->_hiddenLabel = $hiddenLabel;
+ }
+ function toHtml(){
+ $this->_generateId();
+ if ($this->_hiddenLabel){
+ return '<label class="accesshide" for="'.$this->getAttribute('id').'" >'.
+ $this->getLabel().'</label>'.parent::toHtml();
+ } else {
+ return parent::toHtml();
+ }
+ }
+ /**
+ * Automatically generates and assigns an 'id' attribute for the element.
+ *
+ * Currently used to ensure that labels work on radio buttons and
+ * checkboxes. Per idea of Alexander Radivanovich.
+ * Overriden in moodleforms to remove qf_ prefix.
+ *
+ * @access private
+ * @return void
+ */
+ function _generateId()
+ {
+ static $idx = 1;
+
+ if (!$this->getAttribute('id')) {
+ $this->updateAttributes(array('id' => 'id_'. substr(md5(microtime() . $idx++), 0, 6)));
+ }
+ } // end func _generateId
/**
* set html for help button
*
* @return moodleform
*/
function moodleform($action, $customdata=null, $method='post', $target='', $attributes=null) {
- $this->_formname = rtrim(get_class($this), '_form');
+ //strip '_form' from the end of class name to make form 'id' attribute.
+ $this->_formname = preg_replace('/_form$/', '', get_class($this), 1);
$this->_customdata = $customdata;
$this->_form =& new MoodleQuickForm($this->_formname, $method, $action, $target, $attributes);
} else {
$id = $element->getName();
}
- $element->updateAttributes(array('id'=>'id_'.$id));
+ $id = preg_replace('/^qf_/', '', $id, 1);
+ if (strpos($id, 'id_') !== 0){
+ $element->updateAttributes(array('id'=>'id_'.$id));
+ }
parent::renderElement($element, $required, $error);
}
function finishForm(&$form){
$mform->addElement('htmleditor', 'intro', get_string('intro', 'data'));
$mform->setType('intro', PARAM_RAW);
- $mform->addRule('intro', get_string('required'), 'required', null, 'client');
+ $mform->addRule('intro', null, 'required', null, 'client');
$mform->addElement('date_selector', 'timeavailablefrom', get_string('availablefromdate', 'data'), array('optional'=>true));