preRemove - function
preRemove - function
MadMax76
Posts: 149Questions: 33Answers: 1
HI,
I have the following function in my definition:
editor_chat
.on('preRemove', function (val, data, callback) {
if ( data.chat_pid === 3) {return true;}
else {return false;}
});
this should forbid delete for everyone apart from PID 3. At the moment this doesnt - can you see any error?
Thanks
Max
This question has accepted answers - jump to:
This discussion has been closed.
Answers
My only thought is whether
chat_pid
is a string, so the test should bedata.chat_pid === '3'
. It would be worth displaying data withconsole.log()
to see what the values are.Colin
Hi Colin,
there gets no output into the console, but I "found" an error
Uncaught TypeError: data is undefined
As in preRemove there really seems to be no "data", I now tried this instead:
But again I get the same error.
Thanks
Max
Hi Max,
Is this on the client-side (i.e.
preRemove
)? If so, that event is not cancellable.If you need to cancel a delete action it either needs to be done before the data is submitted to the server (
preSubmit
) or you need to do it at the server-side.Is
chat_pid === 3
referring to a row in the data, or to the logged-in user's session, or something else?Should be
undefined
- assuming you have a field in the Editor form calledchat_pid
thendata.data[key].chat_pid
would be the way to access it. If that is giving you an error, I'd need a link to a page showing the issue please.Allan
i have the preSubmit likethis:
in the console I only get this:
I would start with adding
console.log( data );
between lines 2 and 3 to see the structure of thedata
parameter.The
data.data[key]['chat_pid'] === 3
statement on line 3 is a comparison statement not an assignment.Kevin
On this example if you pop open your browser's console and enter:
You'll get the console output the
first_name
value from any rows you submit.Do you have anything else modifying the data structure perhaps? Failing that, and Kevin's suggestion, we'd need to see a link to a page showing the issue.
Allan
I did set up a test case:
http://freigabe.kontura.at/test/allan2.html
BUT: here it also does not work, but no error is showing and nothing comes into the console?!
Thanks
Max
I'm getting an error at that link I'm afraid:
Allan
Sorry we switched site when implementing ssl:
https://portal.kontura.at/test/allan2.html
Thanks! This is what I am getting in the console when I attempt to edit the first row in the first table:
I'm not seeing the
data: undefined
that you described above?Allan
Hi Allan,
sorry the error is coming from another part of the function, which I eliminated in your test-page as it is calling further functions ....(and that part does work although showing an error)
So yes there are no errors shown, and the console shows the values expected, BUT: the presubmit does not stop from deleting entries that have been made by someone else.
I tried this
and this
no success...
Thanks
Max
Hi Max,
Apologies, I've not had a chance to look at this today. I will do so first thing tomorrow.
Allan
There are a few key issues with the
preSubmit
event handler used:data.chat_pid
doesn't exist - it should bevalues.chat_pid
inside the $.each, which is looping overdata.data
.=== 32
should be== 32
in this case or=== '32'
return
statements used are inside the$.each
callback function, so won't return from the `e-event preSubmit callback.Try this:
I may had inverted the logic - I wasn't 100% clear on what the logic is doing here or if the 32 is dynamic or not.
Regards,
Allan
Hi Allan,
i changed this (with valueS instead of value) to
and now it works!
But I also have this code:
This code (due to the called function I can not set it up in the test-page) also works. But: On doing a delete I get the "Uncaught TypeError: data is undefined" pointing at this code, and this editor is dead afterwoods.
I tried this
but this doesn't change anything.
Thanks!
Max
Yep,
data
would beundefined
on aremove
, but I'm surprised your test for'remove'
isn't capturing, as it's doing the trick here: http://live.datatables.net/jaxenisi/1/editWhat is
action
for you when you do a deletion? It would be worth adding debug to understand why it still goes into thatajax_call
.Colin
Hi Colin,
the delete isnt standard (maybe I think too complex ) but I in fact have an edit, as I only set a delete-marker....
So I changed the condition to action == 'create'
Now everything works
THANKS!
Max