javascriptjqueryjquery-dirtyforms

How can I exclude controls from making form Dirty?


I'm using this: $('form').dirtyForms(); from https://github.com/snikch/jquery.dirtyforms to check if my form is dirty. However, on my page I have some dropdown's that are simply used for filtering (they should not make my form "dirty"). Right now when I select any of these drop down's it causes my form to become dirty. Using jquery.dirtyforms (I read their docs but do not see how), how do I exclude selectors (dropdowns, textboxes, etc.) maybe via a class name so that they do not mark the form as dirty.

I tried various things like assigning these dropdowns / filters a class called ignoreDirty then in my jquery I did this:

$('form').dirtyForms().ignoreClass('ignoreDirty');

This produces an error, so I must be doing something wrong. Note I've also tried setting it via property:

$('form').dirtyForms({ ignoreClass : "ignoreDirty" });

But this still makes my form dirty for any control whose class name is still ignoreDirty Please note these filters cause postbacks but lets say I go to my form and have not made a single change. I start clicking on these filters and the minute they post back this happens:

enter image description here


Solution

  • There seems to be 2 different issues here.

    First of all, you are attempting to set the ignoreClass to ignoredirty. ignoredirty is the default value, so there is no reason to set it. However, if you do need to set it to something else, you can do so using the syntax:

    $.DirtyForms.ignoreClass = 'my-ignore-class';
    

    Secondly, in version 1.0.0 the ignoreClass only worked on Hyperlinks. This behavior has been amended to work with input and selection elements in version 1.1.0.

    In version 1.2.0, you can now also set the ignoreClass to parent container elements to ignore input or clicks from any element within.