mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #4306 from gregsmirnov/pulls/3.1/fixed-datetimefield-setname-issue-4305
Issue #4305: fixed DatetimeField::setName()
This commit is contained in:
commit
aa3871d716
@ -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(
|
||||
|
@ -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(),
|
||||
|
Loading…
Reference in New Issue
Block a user