getFormatter showing unwanted raw DB values in Editor

getFormatter showing unwanted raw DB values in Editor

imarderimarder Posts: 7Questions: 4Answers: 1

I am having a problem with 2 x ->getFormatter( ) to display as desired in the Editor
I have 2 DB fields.

  1. "scheduledpickup", stores in Y-m-d H:i:s format (although I am never really interested in the seconds, but I am stuck with it as MySQL only has this datetime format)
  2. "actualpickup", stores in Y-m-d format

My .php file has this

Field::inst( 'scheduledpickup' )
    ->validator( Validate::dateFormat( 'd M Y H:i' ) )
    ->getFormatter( Format::datetime( 'Y-m-d H:i:s', 'd M Y H:i' ) )
    ->setFormatter( Format::datetime( 'd M Y H:i', 'Y-m-d H:i:s' ) ),
Field::inst( 'actualpickup' )
    ->validator( Validate::dateFormat( 'd M Y' ) )
    ->getFormatter( Format::dateSqlToFormat( 'Y-m-d' ) )
    ->setFormatter( Format::dateFormatToSql( 'd M Y' ) ),

My editor fields look like this
[{label: "Scheduled Pickup:",name: "scheduledpickup", type: 'datetime', format: 'DD MMM YYYY HH:mm'},
{label: "Actual Pickup:",name: "actualpickup", type: 'datetime', format: 'DD MMM YYYY'}]

The problem is that when I spawn the editor on a selected data row, the initial value on the fields are respectively e.g.
2018-05-04 08:06:00
i.e. the raw database values and not formatted as I would have expected ->getFormatter to do.

But only after clicking in either field and selecting a datetime (or date), does the display show in the format that I was expecting. e.g. 11 May 2018 08:24

->validator works as expected when a new chosen datetime or date is in the d M Y H:i format or d M Y format
->setFormatter works as expected to convert the validated formats above correctly into the DB

It appears that only the ->getFormatter( Format::datetime()) is not doing its job in displaying in the more human friendly format in the editor

How can one correct this?

thank you.


  • imarderimarder Posts: 7Questions: 4Answers: 1

    In reading other posts further, looks like this is not so straightforward possible.
    I may end up just modifying the initial data read.

  • allanallan Posts: 46,169Questions: 1Answers: 6,405 Site admin

    Can you give me a link to the page showing the issue please? It should be quite possible to have Editor never show the ISO8601 date.


Sign In or Register to comment.