getFormatter showing unwanted raw DB values in Editor

getFormatter showing unwanted raw DB values in Editor

imarderimarder Posts: 12Questions: 5Answers: 2

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
and
2018-05-10
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.

Answers

  • imarderimarder Posts: 12Questions: 5Answers: 2

    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: 63,498Questions: 1Answers: 10,471 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.

    Allan

  • imarderimarder Posts: 12Questions: 5Answers: 2

    Thanks Allan,
    I have 2 test pages that use the same data but behave and display differently

    https://estonia.org.au/testdate/testdate1.html

    php Editor looks like this

    Editor::inst( $db, 'testdate', 'id' )
        ->fields(
            Field::inst( 'olddate' )
                ->validator( Validate::dateFormat( 'd M Y' ) )
                ->getFormatter( Format::dateSqlToFormat( 'Y-m-d', 'd M Y' ) )
                ->setFormatter( Format::dateFormatToSql( 'd M Y', 'Y-m-d' ) ),
            Field::inst( 'newdate' )
                ->validator( Validate::dateFormat( 'd M Y H:i' ) )
                ->getFormatter( Format::datetime( 'Y-m-d H:i:s', 'Y-m-d H:i:s' ) )
                ->setFormatter( Format::datetime( 'd M Y H:i', 'Y-m-d H:i:s' ) ),
            Field::inst( 'description' )
        )
        ->process( $_POST )
        ->json();
    

    https://estonia.org.au/testdate/testdate2.html
    php Editor looks like this

    Editor::inst( $db, 'testdate', 'id' )
        ->fields(
            Field::inst( 'olddate' )
                ->validator( Validate::dateFormat( 'd M Y' ) )
                ->getFormatter( Format::dateSqlToFormat( 'Y-m-d', 'd M Y' ) )
                ->setFormatter( Format::dateFormatToSql( 'd M Y', 'Y-m-d' ) ),
            Field::inst( 'newdate' )
                ->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( 'description' )
        )
        ->process( $_POST )
        ->json(); ) )
    

    So
    A. I do not understand why it shows Invalid Date in testdate2.html
    B. Why it comes up with the ISO date/datetime in the editor. As when it does it will not validate.

    thank you

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    A. I do not understand why it shows Invalid Date in testdate2.html

    Remove the createdCell callback in your table.testdate2.js file. There you are attempting to format a string which is already formatted!

    B. Why it comes up with the ISO date/datetime in the editor. As when it does it will not validate.

    Try loading Moment before you load Editor.

    Thanks,
    Allan

This discussion has been closed.