How to return error message after canceling a preRemove server side event
How to return error message after canceling a preRemove server side event
Following the discussion:
https://datatables.net/forums/discussion/comment/114990/#Comment_114990
I can check the data and cancel the deletion of the row using "return false"
->on( 'preRemove', function ( $editor, $id, $values ) {
$editor->validator( function ( $editor, $action, $data ) {
... some validator logic
return false;
} );
} )
I would like to have an example of how I can also return an error message...
thank you,
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
I think you've hit a limitation with the global validator here. Individual fields can return an error message, but not the global one (yet).
Allan
I found a way faster even if not very elegant to check if the value of "DT_RowId" is present in other tables and therefore can not be deleted.
But the problem of how to display a warning message remains unsolved...
Hopefully I am not necro'ing a thread here, but I thought this would be relevant.
When an exception is thrown, DataTables displays that message to the user.
Is there any negative consequences in manually throwing an exception here?
Example:
Not as far as I'm aware. Editor's libraries do a try/catch by default and will show the exception text to the user. It will also rollback the database since it performs its db actions in a transaction by default.
Good suggestion that - thanks.
Allan
I've just been looking at this, and I'd forgotten at the time that you can just use
return 'Error message...';
in a global validator to have it show as an error! Thethrow
suggestion above is another option.Allan