How to detect changes before submit

How to detect changes before submit

reidevelopmentreidevelopment Posts: 12Questions: 4Answers: 0

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

  • rf1234rf1234 Posts: 2,991Questions: 87Answers: 421
    edited June 2022 Answer ✓

    Is there a value that will show me the original values?

    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.)

  • reidevelopmentreidevelopment Posts: 12Questions: 4Answers: 0

    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"

  • reidevelopmentreidevelopment Posts: 12Questions: 4Answers: 0

    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.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Excellent - thanks for posting back. Good to hear you've got a solution.

    Allan

Sign In or Register to comment.