diff --git a/forms/DatetimeField.php b/forms/DatetimeField.php index 20b84eb79..347795a42 100644 --- a/forms/DatetimeField.php +++ b/forms/DatetimeField.php @@ -63,7 +63,7 @@ class DatetimeField extends FormField { ->addExtraClass('fieldgroup-field'); $this->timeField = TimeField::create($name . '[time]', false) ->addExtraClass('fieldgroup-field'); - $this->timezoneField = new HiddenField($this->getName() . '[timezone]'); + $this->timezoneField = new HiddenField($name . '[timezone]'); parent::__construct($name, $title, $value); } @@ -77,6 +77,14 @@ class DatetimeField extends FormField { 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()) { $config = array( diff --git a/tests/forms/DatetimeFieldTest.php b/tests/forms/DatetimeFieldTest.php index 7802bf444..d21dba211 100644 --- a/tests/forms/DatetimeFieldTest.php +++ b/tests/forms/DatetimeFieldTest.php @@ -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() { return new Form( new Controller(),