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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

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


2040 Views

Avatar
Matze0681

Community Member, 25 Posts

8 December 2010 at 2:15pm

Edited: 08/12/2010 2:23pm

hi,

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.

TableListField.php
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
matze