Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

TableListField: Field Casting with Date->Nice

Go to End



Community Member, 25 Posts

8 December 2010 at 2:15pm

Edited: 08/12/2010 2:23pm


stumbled about a problem with fieldcasting in the tablelistfield. If i define a field casting for a Date field like this:

$fields['DepartureDate'] = array('title' => 'Departure Date',
						'formatting' => '$value',
						'casting' => 'Date->Nice');

and there are empty values in the Result of the TableListField┬┤s SourceQuery, the empty values are casted as well which results in wrong dates: " 01/01/1970" .

It seems that the TableListField always tries to "Cast" a fields value even if its value is empty.

Line: 1357-1362

// casting
if(array_key_exists($fieldName, $this->parent->fieldCasting)) {
        $value = $this->parent->getCastedValue($value, $this->parent->fieldCasting[$fieldName]);
} elseif(is_object($value) && method_exists($value, 'Nice')) {
	$value = $value->Nice();

is there a way to avoid that empty values are casted in the TableListField?

thanks in advance