Editor Field of type "datetime"
Editor Field of type "datetime"
Hello all,
I am struggling with the following problem:
I implemented a datetime field in my editor instance which works just fine. But when the editor instance is opening, the current date/time is already set.
As the date sometimes need to be NULL in my MySQL database, I wondered on how to disable setting the current date/time on opening the editor instance.
Furthermore, when I use the datetimepicker field on IOS it seems to have some trouble opening (it opens very shortly and closes directly afterwards). I then need to reclick on it in order to work.
Does anyone have a solution for this?
Thank you very much for your time!
Cheers,
Paul
This question has an accepted answers - jump to answer
Answers
That would be the case by default, see here, so it must be due to your code or data.
Are you able to link to your page or create a test case? If not, can you paste your code here, please.
Colin
In Colin's example it doesn't do it. Here is a more complex example with the following featuers:
- default date is today (maybe you are setting it in your code as well?! Then just get rid of it!)
- 40 year range in the date picker
- language specific date masking
- language specific (momentLocale) date formatting with moment.js
- show week numbers in the date picker
This should give you an overview on what you can do (momentLocale and today are global variables).
Hey,
thanks for your answer already!
I might need to add the following to underline my problem better:
I have 2 timestamp values in my table. One of them is set to CURRENT_TIMESTAMP on inserting a new entry into my MySQL-database (in mysql).
I fixed the issue where the date was already displayed. It was a mistake within my code.
Both datetime/timestamp values are not editable in the editor instance (because they are set using triggers in Mysql). If I insert an entry with DataTables now, he sets the current_timestamp for both fields, even though only one should be set.
If I make an entry in the backend, it works just fine (only 1 field gets set).
Sorry for the questions!
Thanks a lot!
Quick update:
I figured out my mistake.
The second timestamp field will be set when another value is inserted into a column.
Since this column was not set to ->setFormatter( Format::ifEmpty( null )) it always got populated by inserting.
Sorry for the obvious mistake and thanks to everyone who helped!
Enjoy your evening
Well, either leave it out in the Editor instance server side. Or use ->set( false ) to make sure Editor doesn't try to insert or update the field.
https://editor.datatables.net/manual/php/conditions#Setting-field-values