Merge pull request #4306 from gregsmirnov/pulls/3.1/fixed-datetimefield-setname-issue-4305

Issue #4305: fixed DatetimeField::setName()
This commit is contained in:
Daniel Hensby 2015-06-18 22:10:13 +01:00
commit aa3871d716
2 changed files with 27 additions and 1 deletions

View File

@ -63,7 +63,7 @@ class DatetimeField extends FormField {
->addExtraClass('fieldgroup-field'); ->addExtraClass('fieldgroup-field');
$this->timeField = TimeField::create($name . '[time]', false) $this->timeField = TimeField::create($name . '[time]', false)
->addExtraClass('fieldgroup-field'); ->addExtraClass('fieldgroup-field');
$this->timezoneField = new HiddenField($this->getName() . '[timezone]'); $this->timezoneField = new HiddenField($name . '[timezone]');
parent::__construct($name, $title, $value); parent::__construct($name, $title, $value);
} }
@ -78,6 +78,14 @@ class DatetimeField extends FormField {
return $this; return $this;
} }
public function setName($name) {
parent::setName($name);
$this->dateField->setName($name . '[date]');
$this->timeField->setName($name . '[time]');
$this->timezoneField->setName($name . '[timezone]');
}
public function FieldHolder($properties = array()) { public function FieldHolder($properties = array()) {
$config = array( $config = array(
'datetimeorder' => $this->getConfig('datetimeorder'), 'datetimeorder' => $this->getConfig('datetimeorder'),

View File

@ -214,6 +214,24 @@ class DatetimeFieldTest extends SapphireTest {
); );
} }
public function testGetName() {
$field = new DatetimeField('Datetime');
$this->assertEquals('Datetime', $field->getName());
$this->assertEquals('Datetime[date]', $field->getDateField()->getName());
$this->assertEquals('Datetime[time]', $field->getTimeField()->getName());
$this->assertEquals('Datetime[timezone]', $field->getTimezoneField()->getName());
}
public function testSetName() {
$field = new DatetimeField('Datetime', 'Datetime');
$field->setName('CustomDatetime');
$this->assertEquals('CustomDatetime', $field->getName());
$this->assertEquals('CustomDatetime[date]', $field->getDateField()->getName());
$this->assertEquals('CustomDatetime[time]', $field->getTimeField()->getName());
$this->assertEquals('CustomDatetime[timezone]', $field->getTimezoneField()->getName());
}
protected function getMockForm() { protected function getMockForm() {
return new Form( return new Form(
new Controller(), new Controller(),