Hide Duplicate Example Form

Hide Duplicate Example Form

JWJW Posts: 13Questions: 4Answers: 0

Howdy,

I have a working (modified) example of the Duplicate button code. The actual DT example from the documentation is listed below. Currently, the example will pop-up the form once you select a row and hit the Duplicate button. What I'd like to happen is for the form not to appear at all. While I know it's possible create a new row in the table without showing the form via:

{
    extend: "create",
    text: "New",
    action: function (e, dt, node, config) {
       editor
           .create(false)
           .submit();
       }
}

There's no real way to pass false (at least that I can tell) to the .mode(create) method shown below.

{
                extend: "selected",
                text: 'Duplicate',
                action: function ( e, dt, node, config ) {
                    editor
                        .edit( table.rows( {selected: true} ).indexes(), {
                            title: 'Duplicate record',
                            buttons: 'Create from existing'
                        } )
                        .mode( 'create' );
                }
            },

I've tried the following with the .edit method and the 'show' parameter:

text: 'Duplicate',
action: function ( e, dt, node, config ) {
    editor
        .edit( table.rows( {selected: true} ).indexes(), {
            title: 'Duplicate record',
            buttons: 'Create from existing',
            show: false
         } )
         .mode( 'create' );
     }
},

But it's almost like the .mode('create') that's run after, overrides the 'show:false' parameter. Since the .mode() method doesn't have the capability to force the pop-up form to not appear, I'm not sure what I can do. I've searched the forums and documentation but can't find a way to simply click a row, click the Duplicate button, and it submits a new row without the form appearing.

Any help would be appreciated.

Thanks,
J

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    Try this:

    {
                    extend: "selected",
                    text: 'Duplicate',
                    action: function ( e, dt, node, config ) {
                        editor
                            .edit( table.rows( {selected: true} ).indexes(), false, {
                                title: 'Duplicate record',
                                buttons: 'Create from existing'
                            } )
                            .mode( 'create' );
                    }
                },
    

    The edit() method can actually accept three parameters, a show parameter similar to the one that create() can accept, is an optional second parameter, which I've added above.

    Regards,
    Allan

  • JWJW Posts: 13Questions: 4Answers: 0
    edited February 2018

    Howdy Allan,

    Thank you very much. I saw that show parameter in the API documentation and thought I was coding it correctly (as seen in the OP) but obviously not. I tried your solution in my own application and then, when that didn't bring about the correct results, I even edited the Duplicate Button Example file downloaded as part of the Editor download, and added the 'false' to the parameter in that file as well. In both instances, once I made the change, I selected a row, clicked the 'Duplicate' button and no new row is created and no errors show up. I'll try to put it up on JS Bin just so you can see as well.

    J

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Answer ✓

    Oops! I forgot the submit() call:

    {
                    extend: "selected",
                    text: 'Duplicate',
                    action: function ( e, dt, node, config ) {
                        editor
                            .edit( table.rows( {selected: true} ).indexes(), false, {
                                title: 'Duplicate record',
                                buttons: 'Create from existing'
                            } )
                            .mode( 'create' )
                            .submit();
                    }
                },
    

    That should do it.

    Allan

  • JWJW Posts: 13Questions: 4Answers: 0

    Yup. That did it! Thank you. I should have been able to figure that out myself given that submit() was shown in one of the edit() examples.

    In trying to figure out, why I couldn't figure this out myself (because given 20/20 hindsight, I should have been able to figure this out via the API documentation), I think I've identified what happened on my end. However, in an effort to keep the integrity of the OP, I'll post the question I have in another thread.

    Thanks again, Allan!

This discussion has been closed.