preRemove User Side Notification
preRemove User Side Notification
Restful Web Services
Posts: 202Questions: 49Answers: 2
in Editor
With this very basic example of validating whether or not a row can be deleted how do I present a notification to the user on the client side if the row cannot be removed?
->on( 'preRemove', function ( $editor, $id, $values ) {
if($values['t_emailtemplate']['emailtemplate_id'] == 31){
return false;
}
})
I can see the JSON response is,
{"data":[],"cancelled":["row_31"],"debug":[]}
Is it possible to use this reponse to trigger a notification to the user, i.e. Row 31 could not be removed.
Thanks
This discussion has been closed.
Answers
At the moment you need to use either a simple
alert()
or a third party notification library. Listen for thesubmitComplete
event and check to see if there are anycancelled
rows in the returned JSON. Then you can show the notification.Allan
Hi Allan,
Thanks for the response. In the end I have decided to prevent the delete rather than deal with any responses.
In this simple example I have an
mJoin
table containing bookings linked to the parent client table. If a booking exists the client cannot be deleted so I simply sum the length of the joined records and if the result is greater than 0 then I trigger a notification to the user rather than allow the delete.Chris
For anyone interested I have changed the approach slightly to the below as this easily allows me to potentially check various separate conditions which could prevent the delete from being allowed. It also allows me to include the specific identifiers of the items blocking the delete which will be useful to the user.
I have tried to write the code as succinctly and in a reusable way but any suggestions welcome!