getFormatter showing unwanted raw DB values in Editor
getFormatter showing unwanted raw DB values in Editor
I am having a problem with 2 x ->getFormatter( ) to display as desired in the Editor
I have 2 DB fields.
- "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)
- "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
In reading other posts further, looks like this is not so straightforward possible.
I may end up just modifying the initial data read.
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
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
https://estonia.org.au/testdate/testdate2.html
php Editor looks like this
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
Remove the
createdCell
callback in yourtable.testdate2.js
file. There you are attempting to format a string which is already formatted!Try loading Moment before you load Editor.
Thanks,
Allan