diff --git a/src/Forms/TimeField.php b/src/Forms/TimeField.php
index 14fc20ff8..282963aa9 100644
--- a/src/Forms/TimeField.php
+++ b/src/Forms/TimeField.php
@@ -373,6 +373,14 @@ class TimeField extends TextField
{
/** @var TimeField_Readonly $result */
$result = $this->castedCopy(TimeField_Readonly::class);
+ $result
+ ->setValue(false)
+ ->setHTML5($this->html5)
+ ->setTimeFormat($this->timeFormat)
+ ->setTimezone($this->getTimezone())
+ ->setLocale($this->locale)
+ ->setTimeLength($this->timeLength)
+ ->setValue($this->value);
return $result;
}
diff --git a/src/Forms/TimeField_Readonly.php b/src/Forms/TimeField_Readonly.php
index 40cebf5af..c7cb276a2 100644
--- a/src/Forms/TimeField_Readonly.php
+++ b/src/Forms/TimeField_Readonly.php
@@ -9,18 +9,11 @@ use SilverStripe\Core\Convert;
*/
class TimeField_Readonly extends TimeField
{
-
protected $readonly = true;
-
- public function Field($properties = array())
+ protected $disabled = true;
+
+ public function Type()
{
- if ($this->valueObj) {
- $val = Convert::raw2xml($this->valueObj->toString($this->getConfig('timeformat')));
- } else {
- // TODO Localization
- $val = '(not set)';
- }
-
- return "ID() . "\">$val";
+ return 'readonly';
}
}
diff --git a/tests/php/Forms/TimeFieldReadonlyTest.php b/tests/php/Forms/TimeFieldReadonlyTest.php
new file mode 100644
index 000000000..f32f69d06
--- /dev/null
+++ b/tests/php/Forms/TimeFieldReadonlyTest.php
@@ -0,0 +1,46 @@
+performReadonlyTransformation();
+ $this->assertInstanceOf(TimeField_Readonly::class, $roField);
+
+ $this->assertTrue($roField->isReadonly());
+ $this->assertEquals($roField->dataValue(), '23:00:00');
+ }
+
+ public function testSettingsCarryOver()
+ {
+ $field = new TimeField('Time', 'Time');
+ $field
+ ->setHTML5(false)
+ ->setTimeFormat('KK:mma')
+ ->setTimezone('America/Halifax')
+ ->setLocale('en_US')
+ ->setTimeLength(IntlDateFormatter::SHORT)
+ ->setValue('23:00:00');
+
+ $roField = $field->performReadonlyTransformation();
+ $this->assertFalse($roField->getHTML5());
+ $this->assertEquals($roField->getTimeFormat(), 'KK:mma');
+ $this->assertEquals($roField->getTimezone(), 'America/Halifax');
+ $this->assertEquals($roField->getLocale(), 'en_US');
+ $this->assertEquals($roField->getTimeLength(), IntlDateFormatter::SHORT);
+ }
+}