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

ASP Net Hidden fields and Telerik drama #60

Closed p10tyr closed 9 years ago

p10tyr commented 9 years ago

I know who uses this crap still... apprantly big public companies.

Problem spotted when I want to vcalidata all pages and a simple page with postback selector caused issues because of Telerik radcontorllor hidden input chaning and failing the brute force checker.

My Fix

 var getValue = function ($field) {
            debugger;
            if ($field.hasClass('ays-ignore')
                || $field.hasClass('aysIgnore')
                || $field.attr('data-ays-ignore')
                || $field.closest('.aspNetHidden')  // <-----------------------
                || $field.attr('name') === undefined) {
                return null;
            }

Just ignore all asp hidden values and viewstates and all that or possible allow to pass in extra classes in the options to ignore on.

image

The moment where you test the field, and this hidden one tests true even though the user did not touch this. Maybe Hiddens should be completely ignore??

image

p10tyr commented 9 years ago

Just realised this moonrise, using closest always evaluates to true, well in my case: because it right at the start of the DOM.

So instead I added to ignore hidden fields, since I am not bothered about that. I sometimes update hidden fields (in other projects) to submit data even if no form is there.

In this issue, I start the script on all pages because there is allot of data input. So I really don't want to validate hidden helpers.

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

Another way to do this without modifying are-you-sure's code would be to use a jquery expression to add the ays-ignore class before loading Are-you-sure . e.g.


$('form').find(':hidden').addClass('ays-ignore');
$('form').areYouSure();