ENHANCEMENT removed needless list from CheckboxGroupField and RadioField

This commit is contained in:
Franco Springveldt 2017-07-11 18:16:05 +12:00
parent 93c25b764f
commit 1b472cda7b
6 changed files with 54 additions and 4 deletions

View File

@ -18,8 +18,9 @@ class EditableCheckboxGroupField extends EditableMultipleOptionField
public function getFormField()
{
$field = new UserFormsCheckboxSetField($this->Name, $this->EscapedTitle, $this->getOptionsMap());
$field->setFieldHolderTemplate('UserFormsMultipleOptionField_holder');
$field = UserFormsCheckboxSetField::create($this->Name, $this->EscapedTitle, $this->getOptionsMap())
->setFieldHolderTemplate('UserFormsMultipleOptionField_holder')
->setTemplate('UserFormsCheckboxSetField');
// Set the default checked items
$defaultCheckedItems = $this->getDefaultOptions();

View File

@ -28,8 +28,9 @@ class EditableRadioField extends EditableMultipleOptionField
public function getFormField()
{
$field = OptionsetField::create($this->Name, $this->EscapedTitle, $this->getOptionsMap());
$field->setFieldHolderTemplate('UserFormsMultipleOptionField_holder');
$field = OptionsetField::create($this->Name, $this->EscapedTitle, $this->getOptionsMap())
->setFieldHolderTemplate('UserFormsMultipleOptionField_holder')
->setTemplate('UserFormsOptionSetField');
// Set default item
$defaultOption = $this->getDefaultOptions()->first();

View File

@ -0,0 +1,7 @@
<% loop $Options %>
<div class="$Class">
<input id="$ID" class="radio" name="$Name" type="radio" value="$Value.ATT"<% if $isChecked %>
checked<% end_if %><% if $isDisabled %> disabled<% end_if %> <% if $Up.Required %>required<% end_if %> />
<label for="$ID">$Title</label>
</div>
<% end_loop %>

View File

@ -0,0 +1,11 @@
<% if $Options.Count %>
<% loop $Options %>
<div class="$Class">
<input id="$ID" class="checkbox" name="$Name" type="checkbox" value="$Value.ATT"<% if $isChecked %>
checked="checked"<% end_if %><% if $isDisabled %> disabled="disabled"<% end_if %> />
<label for="$ID">$Title</label>
</div>
<% end_loop %>
<% else %>
<p>No options available</p>
<% end_if %>

View File

@ -0,0 +1,15 @@
<?php
class EditableCheckboxGroupFieldTest extends SapphireTest
{
protected static $fixture_file = 'EditableFormFieldTest.yml';
/**
* Tests that this element is rendered with a custom template
*/
public function testRenderedWithCustomTemplate()
{
$checkboxGroup = $this->objFromFixture('EditableCheckboxGroupField', 'checkbox-group');
$this->assertEquals('UserFormsCheckboxSetField', $checkboxGroup->getFormField()->getTemplate());
}
}

View File

@ -0,0 +1,15 @@
<?php
class EditableRadioFieldTest extends SapphireTest
{
protected static $fixture_file = 'EditableFormFieldTest.yml';
/**
* Tests that this element is rendered with a custom template
*/
public function testRenderedWithCustomTemplate()
{
$radio = $this->objFromFixture('EditableRadioField', 'radio-field');
$this->assertEquals('UserFormsOptionSetField', $radio->getFormField()->getTemplate());
}
}