Skip to content

Commit

Permalink
Patch setMarked for radio and checkbox sets
Browse files Browse the repository at this point in the history
  • Loading branch information
nicksagona committed Apr 25, 2016
1 parent a827146 commit e53217e
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/Element/AbstractElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,18 @@ public function setMarked($marked)
$markedValues = (!is_array($marked)) ? [$marked] : $marked;

foreach ($this->childNodes as $child) {

if (in_array($child->getAttribute('value'), $markedValues)) {
$child->setAttribute('selected', 'selected');
} else if (null !== $child->getAttribute('selected')) {
$child->removeAttribute('selected');
if ($child->getNodeName() == 'input') {
if (in_array($child->getAttribute('value'), $markedValues)) {
$child->setAttribute('checked', 'checked');
} else if (null !== $child->getAttribute('checked')) {
$child->removeAttribute('checked');
}
} else {
if (in_array($child->getAttribute('value'), $markedValues)) {
$child->setAttribute('selected', 'selected');
} else if (null !== $child->getAttribute('selected')) {
$child->removeAttribute('selected');
}
}
}
$this->marked = $marked;
Expand Down

0 comments on commit e53217e

Please sign in to comment.