* @var string $style value to use for the style attribute of this HTML tag.
*/
public $style = '';
+ /**
+ * @var mixed $label The label for that component. String or html_label object
+ */
+ public $label;
/**
* @var array class names to add to this HTML element.
*/
} else if (!empty($text)) {
$this->label = new html_label();
$this->label->for = $for;
- if (empty($for) && !empty($this->id)) {
+ if (empty($for)) {
+ $this->generate_id();
$this->label->for = $this->id;
}
$this->label->text = $text;
* variable that will be set if this select is submitted as part of a form.
*/
public $name;
- /**
- * @var mixed $label The label for that component. String or html_label object
- */
- public $label;
/**
* @var string $selectedvalue the option to select initially. Should match one
* of the $options array keys. Default none.
$timeunits[$i] = userdate(gmmktime(12,0,0,$i,15,2000), "%B");
}
$userdatetype = 'month';
+ $currentdate['month'] = $currentdate['mon'];
break;
case 'days':
for ($i=1; $i<=31; $i++) {
$timerselector = self::make($timeunits, $name, $currentdate[$userdatetype]);
$timerselector->label = new html_label();
- $timerselector->label->text = get_string(substr($type, -1), 'form');
+
+ $timerselector->label->text = get_string(substr($type, 0, -1), 'form');
$timerselector->label->for = "menu$timerselector->name";
$timerselector->label->add_class('accesshide');
$timerselector->nothinglabel = '';
* @var boolean $selected Whether or not this option is selected
*/
public $selected = false;
- /**
- * @var mixed $label The label for that component. String or html_label object
- */
- public $label;
public function __construct() {
$this->label = new html_label();
* @var string $maxlength The maxlength attribute of the field (only applies to text type)
*/
public $maxlength;
- /**
- * @var mixed $label The label for that component. String or html_label object
- */
- public $label;
public function __construct() {
$this->label = new html_label();
* @var string $scope Defines a way to associate header cells and data cells in a table
*/
public $scope = '';
+ /**
+ * @var boolean $header Whether or not this cell is a header cell
+ */
+ public $header = false;
/**
* @see lib/moodle_html_component#prepare()
}
} else if ($select->rendertype == 'checkbox') {
$currentcheckbox = 0;
- foreach ($select->options as $option) {
- $html .= $this->checkbox($option, $select->name);
- $currentcheckbox++;
+ // If only two choices are available, suggest using the checkbox method instead
+ if (count($select->options) < 3 && !$select->multiple) {
+ debugging('You are using $OUTPUT->select() to render two mutually exclusive choices using checkboxes. Please use $OUTPUT->checkbox(html_select_option) instead.', DEBUG_DEVELOPER);
+ } else {
+ foreach ($select->options as $option) {
+ $html .= $this->checkbox($option, $select->name);
+ $currentcheckbox++;
+ }
}
}
* @return string the HTML for the <input type="radio">
*/
public function radio($option, $name='unnamed') {
+ static $currentradio = array();
+
+ if (empty($currentradio[$name])) {
+ $currentradio[$name] = 0;
+ }
+
if ($option instanceof html_select_optgroup) {
throw new coding_exception('$OUTPUT->radio($option) does not support a html_select_optgroup object as param.');
} else if (!($option instanceof html_select_option)) {
$option->label->for = $option->id;
$this->prepare_event_handlers($option);
- $output = $this->output_start_tag('span', array('class' => "radiogroup $select->name rb$currentradio")) . "\n";
+ $output = $this->output_start_tag('span', array('class' => "radiogroup $name rb{$currentradio[$name]}")) . "\n";
$output .= $this->label($option->label);
if ($option->selected == 'selected') {
'checked' => $option->selected));
$output .= $this->output_end_tag('span');
-
+ $currentradio[$name]++;
return $output;
}
'class' => $cell->get_classes_string(),
'abbr' => $cell->abbr,
'scope' => $cell->scope);
-
- $output .= $this->output_tag('td', $tdattributes, $cell->text) . "\n";
+ $tagtype = 'td';
+ if ($cell->header) {
+ $tagtype = 'th';
+ }
+ $output .= $this->output_tag($tagtype, $tdattributes, $cell->text) . "\n";
}
}
$output .= $this->output_end_tag('tr') . "\n";