mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX: Fixed issue where TimeField_Readonly would only show "(not set)" instead of the value
This commit is contained in:
parent
91f091f418
commit
bba0f2f72f
@ -373,6 +373,14 @@ class TimeField extends TextField
|
|||||||
{
|
{
|
||||||
/** @var TimeField_Readonly $result */
|
/** @var TimeField_Readonly $result */
|
||||||
$result = $this->castedCopy(TimeField_Readonly::class);
|
$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;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,18 +9,11 @@ use SilverStripe\Core\Convert;
|
|||||||
*/
|
*/
|
||||||
class TimeField_Readonly extends TimeField
|
class TimeField_Readonly extends TimeField
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $readonly = true;
|
protected $readonly = true;
|
||||||
|
protected $disabled = true;
|
||||||
|
|
||||||
public function Field($properties = array())
|
public function Type()
|
||||||
{
|
{
|
||||||
if ($this->valueObj) {
|
return 'readonly';
|
||||||
$val = Convert::raw2xml($this->valueObj->toString($this->getConfig('timeformat')));
|
|
||||||
} else {
|
|
||||||
// TODO Localization
|
|
||||||
$val = '<i>(not set)</i>';
|
|
||||||
}
|
|
||||||
|
|
||||||
return "<span class=\"readonly\" id=\"" . $this->ID() . "\">$val</span>";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
46
tests/php/Forms/TimeFieldReadonlyTest.php
Normal file
46
tests/php/Forms/TimeFieldReadonlyTest.php
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
namespace SilverStripe\Forms;
|
||||||
|
|
||||||
|
use IntlDateFormatter;
|
||||||
|
use SilverStripe\Dev\SapphireTest;
|
||||||
|
use SilverStripe\Forms\TimeField;
|
||||||
|
use SilverStripe\Forms\TimeField_Readonly;
|
||||||
|
use SilverStripe\i18n\i18n;
|
||||||
|
|
||||||
|
class TimeFieldReadonlyTest extends SapphireTest
|
||||||
|
{
|
||||||
|
protected function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
i18n::set_locale('en_NZ');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPerformReadonly()
|
||||||
|
{
|
||||||
|
$field = new TimeField('Time', 'Time', '23:00:00');
|
||||||
|
$roField = $field->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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user