Skip to content

Commit

Permalink
Extend attribute support to Radio sets and Checkbox sets
Browse files Browse the repository at this point in the history
  • Loading branch information
nicksagona committed Jul 3, 2023
1 parent 358d98e commit bdd331f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/Element/CheckboxSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ public function __construct($name, array $values, $checked = null, $indent = nul
'value' => $k
]);

if (is_array($v) && isset($v['value']) && isset($v['attributes'])) {
$nodeValue = $v['value'];
$checkbox->setAttributes($v['attributes']);
} else {
$nodeValue = $v;
}

// Determine if the current radio element is checked.
if (in_array($k, $this->checked)) {
$checkbox->check();
Expand All @@ -92,7 +99,7 @@ public function __construct($name, array $values, $checked = null, $indent = nul
$span->setIndent($indent);
}
$span->setAttribute('class', 'checkbox-span');
$span->setNodeValue($v);
$span->setNodeValue($nodeValue);
$this->addChildren([$checkbox, $span]);
$this->checkboxes[] = $checkbox;
$i++;
Expand Down
9 changes: 8 additions & 1 deletion src/Element/RadioSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ public function __construct($name, array $values, $checked = null, $indent = nul
'value' => $k
]);

if (is_array($v) && isset($v['value']) && isset($v['attributes'])) {
$nodeValue = $v['value'];
$radio->setAttributes($v['attributes']);
} else {
$nodeValue = $v;
}

// Determine if the current radio element is checked.
if ((null !== $this->checked) && ($k == $this->checked)) {
$radio->check();
Expand All @@ -92,7 +99,7 @@ public function __construct($name, array $values, $checked = null, $indent = nul
$span->setIndent($indent);
}
$span->setAttribute('class', 'radio-span');
$span->setNodeValue($v);
$span->setNodeValue($nodeValue);
$this->addChildren([$radio, $span]);
$this->radios[] = $radio;
$i++;
Expand Down

0 comments on commit bdd331f

Please sign in to comment.