How to detect changes before submit
How to detect changes before submit
![reidevelopment](https://secure.gravatar.com/avatar/d4492d279c6ed39111cc5bc1728aa7f4/?default=https%3A%2F%2Fvanillicon.com%2Fd4492d279c6ed39111cc5bc1728aa7f4_200.png&rating=g&size=120)
I have a multi-item edit form set up and it works great. I now have a requirement to notify IT if certain values are changed. I have access to the data on the preSubmit event but it doesn't show me what has changed. Is there a value that will show me the original values? I think there should be because there is a link on the mult-edit form that says "Undo Changes" so I suspect that the original values are being stored.
Does anyone know how to access the previous values so I can compare to see what rows have changed?
This question has an accepted answers - jump to answer
Answers
Yes, take a look at "data" and "items" in the "initEdit" event handler:
https://editor.datatables.net/reference/event/initEdit
You could save the appropriate values in a global variable and compare them on "submitSuccess". (I wouldn't use preSubmit because it is not sure that the update will succeed at that time.)
the example in the initEdit event shows that the items indicate the rows that are going to be edited, but everytime I use table.rows or in my case editordata.rows, it throws an error telling me that table.rows doesn't exist. How do I get to the "table.rows"
I probably marked the answer as answered too soon. I was able to come up with a different solution that I think works. When I create the table, I have an array called "editordata". On the preSubmit event, I use the data element of the event and filter out the editordata rows that are contained in the data element that will be submitted.
I save this as a different array called "oldValues" and then on the submitSuccess event, I compare the oldValues with the json.data values returned and compare.
It works but I think if I could figure out the initEdit - items way, that may be cleaner.
Either way, I have a workable solution.
Excellent - thanks for posting back. Good to hear you've got a solution.
Allan