toggle checkboxes/radio when clicking on label

This commit is contained in:
Roland Gruber 2011-12-10 14:44:56 +00:00
parent c443806058
commit 9e3667e5a8
2 changed files with 15 additions and 9 deletions

View File

@ -1140,13 +1140,18 @@ class htmlRadio extends htmlElement {
$disabled = ' disabled'; $disabled = ' disabled';
} }
// print radio list // print radio list
$counter = 0;
foreach ($this->elements as $label => $value) { foreach ($this->elements as $label => $value) {
$onClick = 'onClick="jQuery(\'input[name=' . $this->name . ']\').attr(\'checked\', false);jQuery(\'#' . $this->name . $counter . '\').attr(\'checked\', true);"';
echo '<div class="nowrap" ' . $onClick . '>';
$selected = ''; $selected = '';
if ($value == $this->selectedElement) { if ($value == $this->selectedElement) {
$selected = ' checked'; $selected = ' checked';
} }
echo '<input type="radio"' . $name . $disabled . $selected . ' value="' . $value . '" tabindex="' . $tabindex . '"> ' . $label . '<br>'; echo '<input type="radio" id="' . $this->name . $counter . '"' . $name . $disabled . $selected . ' value="' . $value . '" tabindex="' . $tabindex . '"> ' . $label;
echo '</div>';
$tabindex++; $tabindex++;
$counter++;
} }
return array($this->name => 'select'); return array($this->name => 'select');
} }
@ -1321,11 +1326,11 @@ class htmlOutputText extends htmlElement {
class htmlInputCheckbox extends htmlElement { class htmlInputCheckbox extends htmlElement {
/** unique name of input element */ /** unique name of input element */
private $name; protected $name;
/** value */ /** value */
private $checked; protected $checked;
/** enabled or disabled */ /** enabled or disabled */
private $isEnabled = true; protected $isEnabled = true;
/** /**
* Constructor. * Constructor.
@ -1368,7 +1373,7 @@ class htmlInputCheckbox extends htmlElement {
if (!$this->isEnabled) { if (!$this->isEnabled) {
$disabled = ' disabled'; $disabled = ' disabled';
} }
echo '<input type="checkbox" name="' . $this->name . '"' . $tabindexValue . $checked . $disabled . '>'; echo '<input type="checkbox" id="' . $this->name . '" name="' . $this->name . '"' . $tabindexValue . $checked . $disabled . '>';
return array($this->name => 'checkbox'); return array($this->name => 'checkbox');
} }
@ -1425,8 +1430,9 @@ class htmlTableExtendedInputCheckbox extends htmlInputCheckbox {
* @return array List of input field names and their type (name => type) * @return array List of input field names and their type (name => type)
*/ */
function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) { function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) {
$onClick = 'onClick="jQuery(\'#' . $this->name . '\').attr(\'checked\',!jQuery(\'#' . $this->name . '\').attr(\'checked\'));"';
if ($this->labelFirst) { if ($this->labelFirst) {
echo '<div class="nowrap">'; echo '<div class="nowrap" ' . $onClick . '>';
echo $this->label; echo $this->label;
echo '</div>'; echo '</div>';
echo "\n</td>\n<td>\n"; echo "\n</td>\n<td>\n";
@ -1435,7 +1441,7 @@ class htmlTableExtendedInputCheckbox extends htmlInputCheckbox {
else { else {
$return = parent::generateHTML($module, $input, $values, $restricted, $tabindex, $scope); $return = parent::generateHTML($module, $input, $values, $restricted, $tabindex, $scope);
echo "\n</td>\n<td>\n"; echo "\n</td>\n<td>\n";
echo '<div class="nowrap">'; echo '<div class="nowrap" ' . $onClick . '>';
echo $this->label; echo $this->label;
echo '</div>'; echo '</div>';
} }

View File

@ -865,8 +865,8 @@ class kolabUser extends baseModule {
$delegateFields = array(); $delegateFields = array();
$delegateContainer = new htmlTable(); $delegateContainer = new htmlTable();
for ($i = 0; $i < sizeof($kolabDelegate); $i++) { for ($i = 0; $i < sizeof($kolabDelegate); $i++) {
$delegateContainer->addElement(new htmlTableExtendedInputCheckbox('delDelegate_' . $i, false, $kolabDelegate[$i])); $delegateContainer->addElement(new htmlOutputText($kolabDelegate[$i]));
$delegateContainer->addElement(new htmlOutputText(_('Delete')), true); $delegateContainer->addElement(new htmlTableExtendedInputCheckbox('delDelegate_' . $i, false, _('Delete'), null, false), true);
} }
$delegateContainer->addElement(new htmlSelect('new_delegate_value', $delegates)); $delegateContainer->addElement(new htmlSelect('new_delegate_value', $delegates));
$delegateContainer->addElement(new htmlTableExtendedInputCheckbox('new_delegate', false, _("Add"), null, false), true); $delegateContainer->addElement(new htmlTableExtendedInputCheckbox('new_delegate', false, _("Add"), null, false), true);