DTE Duplicate button – change value of a field(s)

DTE Duplicate button – change value of a field(s)

coderxcoderx Posts: 45Questions: 7Answers: 0

Hello,

considering the example Duplicate button, how should I correctly proceed to change value of field(s) before duplication?

E.g.:
Imagine you duplicate a person, the field "Site" should stay the same, but other fields should be empty. // This example does not make much sense, but considering the source Duplicate button.

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'
        } )

        // So what should be done here?
        // Before going to mode( 'create' )
        // .setValue("first_name", null);
        // .setValue("last_name", null);
        // .setValue("phone", null);
        .set( 'first_name', "Test name" ) // This works, but it is the correct way?

        .mode( 'create' );
}

Have a great day!

Peter

Replies

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    There are a couple of options:

    1. The way you have done.
    2. Instead of calling edit() on the selected row, instead call create() and then fill in the field value based on the selected row's data (table.rows({selected:true}).data()).

    I'd take the second approach if you are wanting to keep only a single value. Equally, I'd take the first approach if you wanted to remove only a single value!

    Allan

  • coderxcoderx Posts: 45Questions: 7Answers: 0

    That is really great recommendation! Thanks, Allan! :)

This discussion has been closed.