I have a form where I want to warn the user to save their data. it is done with Dirtyforms.
I have a button in my form, that opens up a modal dialog with some extra form. So,
1. I open my form dialog
2. edit (or not) my new form in the dialog
3. close the dialog
4. return to my first form and click away. The dirtyforms not warns me about losing my data.
I checked it in debug mode, I see in my console this:
[DirtyForms] Adding form w0 to forms to watch
[DirtyForms] Storing original value for _csrf
[DirtyForms] Storing original value for Prenajom[r1]
[DirtyForms] Entering: Leaving Event fired, type: click, element: http://k.local/..., class: btn btn-default popup-addon-table and id:
[DirtyForms] Leaving: Not dirty
[DirtyForms] Clearing the beforeunload event
At opening a modal, it fires the leaving event. How can i prevent it?
Thanks!
By default, all anchor tags (
<a>) get an event attached to them that fires the dialog because there is no reasonable way to differentiate between an anchor that leaves the page and one that does not. If you have anchor tags that do not navigate away, you should ignore them so they don't fire the dialog.Option 1
Set the ignoreSelector option to ignore specific fields, anchors, or buttons.
Option 2
Alternatively, add the value of
$.DirtyForms.ignoreClassto any elements you wish to ignore, and Dirty Forms will ignore them.Option 3
If you want to ignore more than one element at a time, you can add the value of
$.DirtyForms.ignoreClass(with the default valuedirtyignore) to a containing element.