Fix invalid markup in SelectionGroup selected values

This commit is contained in:
Will Rossiter 2018-04-05 10:16:25 +12:00
parent 625f7b4eee
commit 2512761587
2 changed files with 29 additions and 2 deletions

View File

@ -2,7 +2,7 @@
<ul class="SelectionGroup<% if extraClass %> $extraClass<% end_if %>"> <ul class="SelectionGroup<% if extraClass %> $extraClass<% end_if %>">
<% loop $FieldSet %> <% loop $FieldSet %>
<% if $Selected %> <% if $Selected %>
<li$Selected> <li class="selected">
$RadioLabel $RadioLabel
$FieldHolder $FieldHolder
</li> </li>
@ -12,7 +12,7 @@
<% else %> <% else %>
<ul class="SelectionGroup<% if extraClass %> $extraClass<% end_if %>"> <ul class="SelectionGroup<% if extraClass %> $extraClass<% end_if %>">
<% loop $FieldSet %> <% loop $FieldSet %>
<li$Selected> <li <% if Selected %>class="selected"<% end_if %>>
<label>{$RadioButton} {$RadioLabel}</label> <label>{$RadioButton} {$RadioLabel}</label>
<% if $FieldList %> <% if $FieldList %>
$FieldHolder $FieldHolder

View File

@ -41,6 +41,33 @@ class SelectionGroupTest extends SapphireTest
$this->assertContains('two view', (string)$listElTwo->div); $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() function testLegacyItemsFieldHolder()
{ {
$items = array( $items = array(