Halting remove event in TableTools
Halting remove event in TableTools
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
Returning
false
frompreSubmit
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 thenbuttons()
to update the buttons to it willclose()
the lightbox. Or you could use a thirdparty notification library.Allan
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,
This logs the message to the console but the editor window opens anyway.
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:
Allan
Great thanks. That worked. I moved that code into preOpen and it worked there too.