Permalink
Browse files

BUGFIX #5833 Duplicate IDs when two similar date formats in Member_Da…

…tetimeOptionsetField containing different delimiters (e.g / and .) replaced to an empty string (from r108001)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@112703 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information...
1 parent 0e3693f commit 7254c00aefddfc8edfb8bc4925fe306a1a39298e @sminnee sminnee committed Oct 18, 2010
Showing with 8 additions and 6 deletions.
  1. +5 −3 security/Member.php
  2. +3 −3 tests/forms/MemberDatetimeOptionsetFieldTest.php
View
@@ -1844,7 +1844,8 @@ function Field() {
$source = $this->getSource();
foreach($source as $key => $value) {
- $itemID = $this->id() . "_" . ereg_replace('[^a-zA-Z0-9]+', '', $key);
+ // convert the ID to an HTML safe value (colons are not replaced, as they are valid in an ID attribute)
+ $itemID = $this->id() . '_' . preg_replace('/[^\.a-zA-Z0-9\-\_]/', '_', $key);
if($key == $this->value) {
$useValue = false;
$checked = " checked=\"checked\"";
@@ -1856,8 +1857,9 @@ function Field() {
$extraClass = $odd ? "odd" : "even";
$extraClass .= " val" . preg_replace('/[^a-zA-Z0-9\-\_]/', '_', $key);
$disabled = ($this->disabled || in_array($key, $this->disabledItems)) ? "disabled=\"disabled\"" : "";
-
- $options .= "<li class=\"".$extraClass."\"><input id=\"$itemID\" name=\"$this->name\" type=\"radio\" value=\"$key\"$checked $disabled class=\"radio\" /> <label title=\"$key\" for=\"$itemID\">$value</label></li>\n";
+ $ATT_key = Convert::raw2att($key);
+
+ $options .= "<li class=\"".$extraClass."\"><input id=\"$itemID\" name=\"$this->name\" type=\"radio\" value=\"$key\"$checked $disabled class=\"radio\" /> <label title=\"$ATT_key\" for=\"$itemID\">$value</label></li>\n";
}
// Add "custom" input field
@@ -47,15 +47,15 @@ function testDateFormatDefaultCheckedInFormField() {
$field = $this->createDateFormatFieldForMember($this->objFromFixture('Member', 'noformatmember'));
$field->setForm(new Form(new MemberDatetimeOptionsetFieldTest_Controller(), 'Form', new FieldSet(), new FieldSet())); // fake form
$parser = new CSSContentParser($field->Field());
- $xmlArr = $parser->getBySelector('#Form_Form_DateFormat_MMMdyyyy');
+ $xmlArr = $parser->getBySelector('#Form_Form_DateFormat_MMM_d__yyyy');
$this->assertEquals('checked', (string) $xmlArr[0]['checked']);
}
function testTimeFormatDefaultCheckedInFormField() {
$field = $this->createTimeFormatFieldForMember($this->objFromFixture('Member', 'noformatmember'));
$field->setForm(new Form(new MemberDatetimeOptionsetFieldTest_Controller(), 'Form', new FieldSet(), new FieldSet())); // fake form
$parser = new CSSContentParser($field->Field());
- $xmlArr = $parser->getBySelector('#Form_Form_TimeFormat_hmmssa');
+ $xmlArr = $parser->getBySelector('#Form_Form_TimeFormat_h_mm_ss_a');
$this->assertEquals('checked', (string) $xmlArr[0]['checked']);
}
@@ -65,7 +65,7 @@ function testDateFormatChosenIsCheckedInFormField() {
$field = $this->createDateFormatFieldForMember($member);
$field->setForm(new Form(new MemberDatetimeOptionsetFieldTest_Controller(), 'Form', new FieldSet(), new FieldSet())); // fake form
$parser = new CSSContentParser($field->Field());
- $xmlArr = $parser->getBySelector('#Form_Form_DateFormat_MMddyyyy');
+ $xmlArr = $parser->getBySelector('#Form_Form_DateFormat_MM_dd_yyyy');
$this->assertEquals('checked', (string) $xmlArr[0]['checked']);
}

0 comments on commit 7254c00

Please sign in to comment.