mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
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:
parent
4950fdf0cb
commit
ca2c814cd9
@ -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) {
|
||||
|
@ -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');
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user