Navigation Menu

Skip to content

Commit

Permalink
Fix invalid markup in SelectionGroup selected values
Browse files Browse the repository at this point in the history
  • Loading branch information
wilr committed Apr 4, 2018
1 parent 625f7b4 commit 2512761
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
4 changes: 2 additions & 2 deletions templates/SilverStripe/Forms/SelectionGroup.ss
Expand Up @@ -2,7 +2,7 @@
<ul class="SelectionGroup<% if extraClass %> $extraClass<% end_if %>">
<% loop $FieldSet %>
<% if $Selected %>
<li$Selected>
<li class="selected">
$RadioLabel
$FieldHolder
</li>
Expand All @@ -12,7 +12,7 @@
<% else %>
<ul class="SelectionGroup<% if extraClass %> $extraClass<% end_if %>">
<% loop $FieldSet %>
<li$Selected>
<li <% if Selected %>class="selected"<% end_if %>>
<label>{$RadioButton} {$RadioLabel}</label>
<% if $FieldList %>
$FieldHolder
Expand Down
27 changes: 27 additions & 0 deletions tests/php/Forms/SelectionGroupTest.php
Expand Up @@ -41,6 +41,33 @@ function testFieldHolder()
$this->assertContains('two view', (string)$listElTwo->div);
}

function testSelectedFieldHolder()
{
$items = array(
new SelectionGroup_Item(
'one',
new LiteralField('one', 'one view'),
'one title'
),
new SelectionGroup_Item(
'two',
new LiteralField('two', 'two view'),
'two title'
),
);
$field = new SelectionGroup('MyGroup', $items);
$field->setValue('two');

$parser = new CSSContentParser($field->FieldHolder());
$listEls = $parser->getBySelector('li');
$listElOne = $listEls[0];
$listElTwo = $listEls[1];

$this->assertEquals('one', (string)$listElOne->label[0]->input[0]['value']);
$this->assertEquals('two', (string)$listElTwo->label[0]->input[0]['value']);
$this->assertEquals('selected', (string)$listElTwo->attributes()->class);
}

function testLegacyItemsFieldHolder()
{
$items = array(
Expand Down

0 comments on commit 2512761

Please sign in to comment.