Halting remove event in TableTools

Halting remove event in TableTools

enielsonenielson Posts: 6Questions: 3Answers: 0
edited November 2014 in Free community support

Hello I've downloaded the Editor trial.

I'm trying to prevent removal of a row if a certain condition is met. I tried to make a testcase on live.datatables.net but I couldn't get the Editor working.

Here is my code:

    editor.on( 'preSubmit', function ( e, data, action ) {
        var rowdata = rule_table.row( '.selected' ).data();
        if(action == "remove" && rowdata.default) {
            return false;
        }
        return true;
    } );

When I click on the remove button the normal remove confirm dialog pops up. After hitting the Delete button in that dialog, the dialog either stays put with no change or the activity-animation circle spins until I close the window. If I return true from this function the row is removed, as expected.

What is the proper way of doing this? I'd like an error dialog for feedback as well.

Thanks!

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    Returning false from preSubmit doesn't close the display since it is typically used for validation and you would want to be able to correct given inputs, rather than immediately dismissing them.

    To close the display use close().

    To display an error message you could either use message() and then buttons() to update the buttons to it will close() the lightbox. Or you could use a thirdparty notification library.

    Allan

  • enielsonenielson Posts: 6Questions: 3Answers: 0
    edited November 2014

    I tried to use close() and then return false but it was sending the POST request anyway. Couldn't figure out why.

    I could also use preOpen but I can't get that to work either.

    I am using tabletools and trying to hook a check when the user presses the delete button. With preOpen I'd like to pop up a notification instead of the delete dialog.

    As a test,

    editor.on( 'preOpen', function ( e ) {
    console.log("preOpen");
    return false;
    } );
    

    This logs the message to the console but the editor window opens anyway.

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    edited November 2014 Answer ✓

    I've just tried this and it seems to work as expected - it need your additional logic for the validation of course, but other than that, it will show the error message and not submit:

        editor.on( 'preSubmit', function ( e, data, action ) {
            if ( action === 'remove' ) {
                editor
                    .message( 'An error has occurred' )
                    .buttons( {
                        label: 'Close',
                        fn: function () {
                            editor.close();
                        }
                    } );
                return false;
            }
        } );
    

    Allan

  • enielsonenielson Posts: 6Questions: 3Answers: 0

    Great thanks. That worked. I moved that code into preOpen and it worked there too.

This discussion has been closed.