Editor Field of type "datetime"

Editor Field of type "datetime"

schwaluckschwaluck Posts: 103Questions: 27Answers: 1

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

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    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

  • rf1234rf1234 Posts: 3,000Questions: 87Answers: 421
    edited July 2020

    But when the editor instance is opening, the current date/time is already set.

    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).

    if (lang === 'de') {
        moment.locale('de');
        momentLocale = 'de';
    } else {
        moment.locale('en-gb');
        momentLocale = 'en-gb';
    }    
    today = moment(MMDDYYYY, "MMDDYYYY").format('L');
    ...............
    ............
    
    }, {
        label: lang === 'de' ? 'Kursdatum:' : 'Rate Date:',
        name:  "bond_rate.date",
        attr: {
            class: dateMask
        },
        type:  "datetime",
        def:   function () { return today},
        format: 'L',
        opts:  {
            showWeekNumber: true,
            yearRange: 40,
            momentLocale: momentLocale
        }
    }, {
    
  • schwaluckschwaluck Posts: 103Questions: 27Answers: 1

    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!

  • schwaluckschwaluck Posts: 103Questions: 27Answers: 1

    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 :)

  • rf1234rf1234 Posts: 3,000Questions: 87Answers: 421
    Answer ✓

    If I insert an entry with DataTables now, he sets the current_timestamp for both fields, even though only one should be set.

    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

This discussion has been closed.