Merge pull request #6841 from open-sausages/pulls/4.0/5706-selection-group-label-wrap-input

Wrap selection group input in label
This commit is contained in:
Chris Joe 2017-04-26 16:51:03 +12:00 committed by GitHub
commit 05ac2c6fc9
3 changed files with 14 additions and 22 deletions

View File

@ -101,17 +101,9 @@ class SelectionGroup extends CompositeField
'name' => $this->name,
'value' => $item->getValue(),
'checked' => $checked,
'aria-labelledby' => "title-{$itemID}",
)
)),
"RadioLabel" => DBField::create_field('HTMLFragment', FormField::create_tag(
'label',
array(
'id' => "title-{$itemID}",
'for' => $itemID
),
$item->getTitle()
)),
"RadioLabel" => $item->getTitle(),
"Selected" => $firstSelected,
);
$newItems[] = $item->customise($extra);

View File

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

View File

@ -31,11 +31,11 @@ class SelectionGroupTest extends SapphireTest
$listElOne = $listEls[0];
$listElTwo = $listEls[1];
$this->assertEquals('one', (string)$listElOne->input[0]['value']);
$this->assertEquals('two', (string)$listElTwo->input[0]['value']);
$this->assertEquals('one', (string)$listElOne->label[0]->input[0]['value']);
$this->assertEquals('two', (string)$listElTwo->label[0]->input[0]['value']);
$this->assertEquals('one title', (string)$listElOne->label[0]);
$this->assertEquals('two title', (string)$listElTwo->label[0]);
$this->assertEquals(' one title', (string)$listElOne->label[0]);
$this->assertEquals(' two title', (string)$listElTwo->label[0]);
$this->assertContains('one view', (string)$listElOne->div);
$this->assertContains('two view', (string)$listElTwo->div);
@ -53,11 +53,11 @@ class SelectionGroupTest extends SapphireTest
$listElOne = $listEls[0];
$listElTwo = $listEls[1];
$this->assertEquals('one', (string)$listElOne->input[0]['value']);
$this->assertEquals('two', (string)$listElTwo->input[0]['value']);
$this->assertEquals('one', (string)$listElOne->label[0]->input[0]['value']);
$this->assertEquals('two', (string)$listElTwo->label[0]->input[0]['value']);
$this->assertEquals('one', (string)$listElOne->label[0]);
$this->assertEquals('two', (string)$listElTwo->label[0]);
$this->assertEquals(' one', (string)$listElOne->label[0]);
$this->assertEquals(' two', (string)$listElTwo->label[0]);
}
function testLegacyItemsFieldHolderWithTitle()
@ -72,10 +72,10 @@ class SelectionGroupTest extends SapphireTest
$listElOne = $listEls[0];
$listElTwo = $listEls[1];
$this->assertEquals('one', (string)$listElOne->input[0]['value']);
$this->assertEquals('two', (string)$listElTwo->input[0]['value']);
$this->assertEquals('one', (string)$listElOne->label[0]->input[0]['value']);
$this->assertEquals('two', (string)$listElTwo->label[0]->input[0]['value']);
$this->assertEquals('one title', (string)$listElOne->label[0]);
$this->assertEquals('two title', (string)$listElTwo->label[0]);
$this->assertEquals(' one title', (string)$listElOne->label[0]);
$this->assertEquals(' two title', (string)$listElTwo->label[0]);
}
}