Invalid date format
Invalid date format
How is it possible, to insert an empty value (or NULL value) with the editor (1.3.3) for a database column with date format?
I use jQueryUI datepicker and if i leave the field blank there comes an error "SQLSTATE[22007]: Invalid datetime format:»«". The database field can be empty and in php-file the date field has no indication for validation.
Thanks for your help
Ralph
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Hi Ralph,
What is the data that is being submitted to the server (you can check using the developer tools in your browser to see the Ajax request)?
With the PHP libraries you can use the
nullEmpty()
formatter to convert an empty string tonull
for the database (since HTTP variables can't benull
- they are just strings.Allan
Hi Allan,
the submitting data for the date-field is empty
OR
see data[start_date]
So i think the getFormatter-call didn't help at this position.
Hi,
Did you try the
getFormatter
? It should translate an empty string into anull
for the database. It sounds like the database is currently rejecting empty (zero length) strings for that column and anull
might be the value that it will accept.Allan
Yes, i think so, table.refs.php looks like
...
Field::inst( 'start_date' )->getFormatter( 'Format::nullEmpty' ),
...
Doh - sorry. I should have said
setFormatter()
! ThegetFormatter()
is for getting the data,setFormatter()
for setting it!Allan
Perfect, thanks for your help
Hi Allan,
the solution is ok for viewing dates in my format (->getFormatter( 'Format::date_sql_to_format', 'm/Y' )). But if i edit the values with datatables editor, date (with and without datepicker) get wrong (add 6 month and 6 years). I try to set ->setFormatter( 'Format::date_format_to_sql', 'yyyy-mm-dd' ) OR ->setFormatter( 'Format::Format::DATE_ISO_8601' ) with no success. Maybe you can help me again.
Thanks
Ralph
Are you editing using the
m/Y
format? Do you also have the set formatter using that format?Allan
No, I just want to view the date in datatable as 'm/Y', for editor I the using is ISO8601.
With setting the getFormatter the date in editor shows wrong, by try to set the setFormatter like i worte above, nothing changed. I try to change the order of set-/getFormatters with no success.
I just want to have two date format for the same column. In the view I want 'm/Y' and when editing the values there I want to select the complete date for saving in database (ISO 8601).
Thanks
Ralph
I see - you want the date in two different formats. So what I would suggest for that is that you have two different
Field
's which describe what you want - only one of them would be used to set the value though:Note the use of the second parameter for the
Field
creation - that is the name that the value is written to in the JSON. So usecolumns.data
to access it:data: 'table_update_date'
.Note also the
set( false )
to ensure that it isn't written to at all.Allan
Hi Allan,
your suggestion didn't help me. The validator part is ok but it wont solve the problem. The date shows still wrong.
The code below is my original code, where the view of table is in format m/Y (or any other without day) and in the editorview the date always show an wrong future date. If i comment out the getFormatter everything works good.
Maybe i have an error in reasoning and it is simple but my ideas run out.
Ralph
Let's step back for a moment. You want:
m/Y
Y/m/d
).Is that correct?
If so, did you try my suggestion above of reading the field from the database using two different
Field
instances? If you want the date in two different formats, that is how I would suggest you do it.Allan
Correct, this is my request.
I try your suggestion. The code i try was:
Maybe I missunderstand you, please correct me if when my code is wrong.
As you can see, I have two date-fields. The database-fieldnames are start_date and end_date.
Thanks
Ralph
Aliasing it to itself isn't going to do any good! If you have a look at my code above, I selected a different name, otherwise you have a name conflict.
Allan
Yes Allan, you are right. I understand you now.
For others with the same problem here the solution:
file: table.TABLE.js
in datatable-code ($('#refs').dataTable) rename the date-column(s) to *_view
file: table.TABLE.php
make two field::inst per date-column, first the one for edit
in my example it is:
Now you see the *_view-column in datatable and the original column in editor.
Thanks for your help Allan
Good to hear we got it working the way you want!
Allan