In the current project I am working on, there was a need to trigger a save changes alert on a group of different pages in case some changes were made on the page, for things like entering data to inputs or checking some checkboxes. The problem was that on certain pages, and sometimes on certain parts of specific pages, I needed to disable this behaviour.
The solution I came up with:
1 2 3 4 5 6 7 8 9 10 11 12
1. If some things were changed on the page, we will mark the changed parameter as true.
2. If we don’t want to use this behaviour on a specific page, we will mark notify_before_close parameter as false.
3. If we want to disable this behaviour for a specific group of inputs, we need to wrap these inputs with a specific class – ‘discard-changes’. For example:
1 2 3 4 5 6 7 8 9 10 11
In this case, changes to name and description input will not trigger a save changes alert. I hope this helps someone out there.