Jump to:

23555 Posts in 19382 Topics by 2892 members

General Questions

SilverStripe Forums » General Questions » TableListField: Field Casting with Date->Nice

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

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

Page: 1
Go to End
Author Topic: 1213 Views
  • Matze0681
    Community Member
    25 Posts

    TableListField: Field Casting with Date->Nice Link to this post


    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

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.