error message by DateTime picker
error message by DateTime picker
Hildeb67
Posts: 64Questions: 18Answers: 1
Hello everyone. I'm using a DateTime picker in German format and would like to store the time and date in a mysql datetime field. I have following code.
fields: [
{
type: 'datetime',
label: "Einsatzbeginn:",
name: "ESBEGINN",
format: 'DD/MM/YYYY HH:mm',
def: () => new Date(),
displayFormat: 'DD.MM.YYYY HH:mm'
}
Field::inst( 'ESBEGINN' )
->validator( Validate::dateFormat(
'j M Y H:i'
) )
->getFormatter( Format::datetime(
'Y-M-d H:i:s',
'j M Y H:i'
) )
->setFormatter( Format::datetime(
'j M Y H:i',
'Y-m-d H:i:s'
) ),
Unfortunately I get the error message 'Input not valid'. What am I doing wrong?
Thanks for your help
This question has an accepted answers - jump to answer
Answers
Hi,
Looks like there are a few things going on - first, don't use
format
anddisplayFormat
together. Either useformat
alone, or usedisplayFormat
andwireFormat
.You would use
format
if the server is sending you formatted data (it is in this case). You would usedisplayFormat
andwireFormat
if you were to have the server send ISO8601 data (which I'd prefer to see).So option 1: Remove
displayFormat
and changeformat
to make the format being sent from the server - in PHP you have'j M Y H:i'
- which in Moment tokens is:D MMM YYYY HH:mm
. That's your fastest route to a fix.Option 2: Remove the get / set formatters at the client-side and use client-side rendering for the dates. Use
DataTable.render.date()
for the column anddisplayFormat
andwireFormat
for Editor. If you have customers who might be using a different locale from you - e.g. American's, then you might want to consider this approach.Allan
Hi Allan,
thanks for the detailed solution but unfortunately it doesn't work for me. Do you have an example for me? Also for the php site? Chris
This is the server-side formatted date example. The PHP script is available by clicking the "Server script" tab below the table.
If you are able to give me a link to your page I can take a look at what is going on.
Allan
Hi Allan,
here is the link to the page
https://www.futuretecaugsburg.de/src/FOM/einsatz_neu.php
The server appears to be responding with just the ISO8601 date part. Not the formatted date as might be expected from:
Can you show me your full PHP code as well please?
Allan
is that sufficient?
Hello Allan, is this the information you need?
Hi,
Apologies for having not been able to reply over the weekend.
I don't actually see:
in your code at all?
Instead it has:
Which results in an ISO8601 date part, which is what is shown in the JSON response screenshot you showed above.
So at the moment, the code is doing what is expected.
What I'm not clear on is where the
j M Y H:i
comes into play? I'd have expected it to be on that field, but it isn't?Allan
Thanks Allan, I've now solved it like this:
Many greetings, Chris
Hi Chris,
Awesome - good to hear you've got it working now.
Allan