Using DTE Duplicate how do I auto-update some fields like Publish in the new $ID?
Using DTE Duplicate how do I auto-update some fields like Publish in the new $ID?
koniahin
Posts: 186Questions: 39Answers: 7
Duplicate, in itself, work fine. However when I duplicate the field I need to:
{
extend: "selected",
text: 'Duplicate',
action: function ( e, dt, node, config ) {
// Start in edit mode, and then change to create
editor
.edit( table.rows( {selected: true} ).indexes(), {
title: 'Duplicate record',
buttons: 'Create from existing'
} )
.mode( 'create' );
}
},
1) Set publish to No
2) With 2 date field I need to update them the first one to now and the second to 30 days ahead. This code gets those values:
$today = date('Y-m-d');
$date_plus_30 = date('Y-m-d', strtotime("+30 days"));
If not using duplicate I do something like:
{
label: 'Date begins (this must be updated)',
name: 'date_begins',
default: '<?php echo $today; ?>',
attr: { placeholder: "Format: YYYY-MM-DD" },
},
{
label: 'Date ends (this must be updated)',
name: 'date_ends',
default: '<?php echo $date_plus_30; ?>',
attr: { placeholder: "Format: YYYY-MM-DD" },
},
However with duplicate those values get overwritten.
This discussion has been closed.
Answers
This example from this thread may help, it's showing how to update fields when duplicating. Hope that helps,
Colin
I looked at the example but it goes above my head. Let's try this a different way. Should the following code added to the controller file work?
->on( 'postCreate', function ( $editor, $id, $values) {
->query( 'update', 'classes' )
->set( 'classes.publish', 'No' )
->where( 'classes.id', $id, '=' )
->exec();
As is, it causes the table to not load with the error:
DataTables warning: table id=datatable - Ajax error. For more information about this error, please see http://datatables.net/tn/7
I would do it on the client-side in this case actually:
Allan
That is much more like it. The last question would be how do you convert the date format to the format I use, 2021-07-03, yyyy-mm-dd ?
There are two datetime options -
displayFormat
andwireFormat
. To change how the field is displayed, tweak thedisplayFormat
.Colin
Neither my contractor nor I could get it to work with the datetime tip. Thinking out of the box I gambled and set the values using PHP
and
That worked.