codedance / jquery.AreYouSure

A light-weight jQuery "dirty forms" Plugin - it monitors html forms and alerts users to unsaved changes if they attempt to close the browser or navigate away from the page. (Are you sure?)
508 stars 145 forks source link

Missing <input> tags from tracking when name attribute is not set #86

Open tbutterwith opened 8 years ago

tbutterwith commented 8 years ago

If an input tag is missing the name attribute <input type='text' id='input'> then it is completely ignored from the dirty forms tracking.

Lines 28-34 (jquery.areYouSure.js) clearly show this as the intention but it's not listed in the docs

 var getValue = function ($field) {
            if ($field.hasClass('ays-ignore')
                || $field.hasClass('aysIgnore')
                || $field.attr('data-ays-ignore')
                || $field.attr('name') === undefined) {
                return null;
            }
codedance commented 8 years ago

Oh. Sorry for the late reply. The github notification ended up in my span bin!

If the field does not have a name attribute it will not be submitted in a form post. The thinking is if it can't modify the post, then the form is not dirty. Do you have a use-case where you need to change this behaviour. I'd be keen to understand. Maybe we could consider putting a configuration option in if required.

tbutterwith commented 8 years ago

Working within a BackboneJs environment submitting forms using the MVC framework. Input tags use data-model-attrib attribute rather than name to identify them when submitting the data.