ENHANCEMENT Allow CheckboxSetField to use extra classes as other FormField classes do. Also dded test for this behaviour in CheckboxSetFieldTest.

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@66625 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sean Harvey 2008-11-25 07:19:20 +00:00 committed by Sam Minnee
parent 4950fdf0cb
commit ca2c814cd9
2 changed files with 10 additions and 3 deletions

View File

@ -82,7 +82,7 @@ class CheckboxSetField extends OptionsetField {
$odd = ($odd + 1) % 2;
$extraClass = $odd ? "odd" : "even";
$extraClass .= " val" . str_replace(' ','',$key);
$itemID = $this->id() . "_" . ereg_replace('[^a-zA-Z0-9]+','',$key);
$checked ="";
@ -95,8 +95,7 @@ class CheckboxSetField extends OptionsetField {
$options .= "<li class=\"$extraClass\"><input id=\"$itemID\" name=\"$this->name[$key]\" type=\"checkbox\" value=\"$key\"$checked $disabled class=\"checkbox\" /> <label for=\"$itemID\">$value</label></li>\n";
}
return "<ul id=\"{$this->id()}\" class=\"optionset\">\n$options</ul>\n";
return "<ul id=\"{$this->id()}\" class=\"optionset checkboxsetfield{$this->extraClass()}\">\n$options</ul>\n";
}
function setDisabled($val) {

View File

@ -4,6 +4,14 @@ class CheckboxSetFieldTest extends SapphireTest {
static $fixture_file = 'sapphire/tests/forms/CheckboxSetFieldTest.yml';
function testAddExtraClass() {
/* CheckboxSetField has an extra class name and is in the HTML the field returns */
$cboxSetField = new CheckboxSetField('FeelingOk', 'Are you feeling ok?', array(0 => 'No', 1 => 'Yes'), '', null, '(Select one)');
$cboxSetField->addExtraClass('thisIsMyExtraClassForCheckboxSetField');
preg_match('/thisIsMyExtraClassForCheckboxSetField/', $cboxSetField->Field(), $matches);
$this->assertTrue($matches[0] == 'thisIsMyExtraClassForCheckboxSetField');
}
function testSaveWithNothingSelected() {
$article = $this->fixture->objFromFixture('CheckboxSetFieldTest_Article', 'articlewithouttags');