Okay
  Public Ticket #2630331
date and time default value
Closed

Comments

  •  1
    Axel started the conversation

    Hi!

    I tried on  your sandbox:

    There must be a small bug in the placeholder system.
    setting %CURRENT_DATETIME% as the default value for a field and adding a new record all works fine, the current date and time are set in the field.
    But...
    Leaving the screen open for at least one minute, and trying to insert a new record, the time automatically entered is one minute ago.
    Same thing for the date or time individually.

    It is clear that% CURRENT_DATETIME%,% CURRENT_TIME% and% CURRENT_DATE% have nothing of "CURRENT" but rather resemble "% the last_time_the_page_was_loaded%" :)

    I need% CURRENT_TIME% to be always up-to-date because whoever enters the data keeps the screen open all day and shouldn't have to reload for each addition.

    Thanks if you want to help.

  •  2,572
    Aleksandar replied

    Hello Axel

    This will be forwarded to our development team, but at the moment there's nothing we can do about it.

    The current time is generated by the placeholder when you open the modal, and if you keep the modal open for a longer period of time it will stay like that. wpDataTables can't yet generate the time in real-time.

    Like I said, this will be forwarded to our developers, and hopefully they'll be able to do something about it in one of our future updates.

    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables

  •  1
    Axel replied

    Hi Aleksandar, thank you for your reply,


    I probably didn't explain well,
    You say: "The current time is generated by the placeholder when you open the modal" but it doesn't work like that.

    It is normal that, with the modal window open, the time does not update, what I mean is that by leaving the window with the table open (not the modal entry window), if you try to open the modal window (New Entry) already after one minute, the date and time does not update.

    You can simply try it out on your sandbox


    Thanks again

    a.

  •  2,572
    Aleksandar replied

    I understand, Axel.

    That's how the plugin works at the moment, unfortunately. Our developer checked this, and said that he's going to create a task to resolve this issue. We'll either refresh it when the modal opens up, or something like that.

    The issue is acknowledged and it will be resolved in the future.

    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables

  •  1
    Axel replied

    Thanks a lot Aleksandar,

    I look forward to the solution.

    On this occasion I point out that another bug afflicts the default values.
    If you set the Editor input type to "Date" "time" or date_time "then it is impossible to insert the placeholder in the default value (the placeholder disappears).
    I found a workaround to do it, you need:
    - set the Editor input type to any other value eg. one-line edit,
    - insert the placeholder
    - and then change the Editor input type again to "Date" "time" or date_time ".

    This keeps the placeholder on Predefined value
    This is also verifiable on your sandbox.

    It might be useful for someone

    Thanks again
    a.

  •  2,572
    Aleksandar replied

    Thank you, Axel, for sharing that with everyone.

    Our developers are aware of this issue, and they will work on it in the future.

    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables

  •  1
    Axel replied

    Hi Aleksandar,
    any news on this issue?

  •  2,572
    Aleksandar replied

    Hello again Axel

    Not yet. Our developers added this as a task for the future, but I can't say when it will be fixed. At the moment, your workaround is the best option there is.

    Please feel free to add it as a feature suggestion on  this page, also.

    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables

  •  1
    Axel replied

    Sorry Aleksandar,
    I was not referring to the bug on generic default values (for which the workaround can be fine) but to the one on the failure to update the date which is much more important and, for the moment, has no alternative solutions.

    Can you confirm that the bug on the default dates is in the works?

    Thank you
    to.

  •  472
    Isidora replied

    Hello  Axel,

    Sorry for the delay in our responses, has been national holidays in our country for the last two days.

    Aleksandar is on vacation and I will help you out.

    Yes, that is a bug and it is forward to our developers. That value for current_datetime is created to replace current DateTime when you insert new data (open edit modal) it is not live DateTime counter that will replace value like in your case, it is just the current date-time value in the moment when you open edit modal(that placeholder is replaced with that value)

    What you can do as a workaround

    function timestamp_for_wpdatatables ( $formdata, $tableId ) {   
        $columnsData = WDTConfigController::loadColumnsFromDB($tableId);
          foreach ($columnsData as $column) {
              if ($column->orig_header == "timestamp") {
                      $formdata["timestamp"] = date("Y-m-d H:i:s");
              } elseif ($column->orig_header == "created" && get_query_var('new_created_for_wpdatatables') == true) {
                     $formdata["created"] = date("Y-m-d H:i:s");
              }
         }
             return $formdata;
     } 
    add_filter('wpdatatables_filter_formdata_before_save', 'timestamp_for_wpdatatables',10,2);
    function created_for_wpdatatables ( $formdata, $tableId ) {
        if ($formdata['wdt_ID'] == '') {
             set_query_var('new_created_for_wpdatatables', true);
         }
         return $formdata;
     } 
    add_filter('wpdatatables_filter_frontend_formdata', 'created_for_wpdatatables',10,2);
    

    This can auto-increment DateTime into columns with headers "timestamp" or "created"

    Best regards

    Kind Regards, 

    Isidora Markovic

    wpDataTables: FAQFacebookTwitterFront-end and back-end demoDocs

    Amelia: FAQFacebookTwitter |  Amelia demo sites | Docs

    You can try our wpDataTables add-ons before purchase on these sandbox sites:

    Powerful FiltersGravity Forms Integration for wpDataTablesFormidable Forms Integration for wpDataTables

  •  1
    Axel replied

    Thank you so much Milan,

    so i will have to adapt your code with my column names and also the format (i just need the time).

    Do you think "orig_header" is the title of the Mysql field or the Displayed header of the table?
    because, in both cases the code doesn't seem to have any effect, the two functions are never called.

    I will let you know.
    When this code becomes useless, if it were possible, could I hear about it?
    Thanks again for your effort.
    a.

  •  472
    Isidora replied

    Hello  Axel,

    Sorry for the late response. 

    We are located in Serbia and our working time is from 10:00 to 17:00 CET. business days.

    Yes, your origin header have to be the same as those values or you can change those values in the hook how is called in your database.

    For example, if you have a column in the database that is called timeValue and updateDate nad like datae is shown as origin headers in the column settings then you will use

    function timestamp_for_wpdatatables ( $formdata, $tableId ) {   
        $columnsData = WDTConfigController::loadColumnsFromDB($tableId);
          foreach ($columnsData as $column) {
              if ($column->orig_header == "timeValue") {
                      $formdata["timeValue"] = date("Y-m-d H:i:s");
              } elseif ($column->orig_header == "updateDate" && get_query_var('new_created_for_wpdatatables') == true) {
                     $formdata["updateDate"] = date("Y-m-d H:i:s");
              }
         }
             return $formdata;
     } 
    add_filter('wpdatatables_filter_formdata_before_save', 'timestamp_for_wpdatatables',10,2);
    function created_for_wpdatatables ( $formdata, $tableId ) {
        if ($formdata['wdt_ID'] == '') {
             set_query_var('new_created_for_wpdatatables', true);
         }
         return $formdata;
     } 
    add_filter('wpdatatables_filter_frontend_formdata', 'created_for_wpdatatables',10,2);
    

    Please note that updateDate will be formatted as DateTime value only for new entries. if the user edits those fields and remove value from this column(leave empty) it will be empty. If you need like for timeValue you will need to remove  get_query_var from the condition.

    These hooks are triggered only when you are editing or adding new entries.

    Kind Regards, 

    Isidora Markovic

    wpDataTables: FAQFacebookTwitterFront-end and back-end demoDocs

    Amelia: FAQFacebookTwitter |  Amelia demo sites | Docs

    You can try our wpDataTables add-ons before purchase on these sandbox sites:

    Powerful FiltersGravity Forms Integration for wpDataTablesFormidable Forms Integration for wpDataTables