This is something I faced building w2p_tvseries. There is a page with 
several tabs and I needed to tell the user to remember to save the changes 
before going elsewhere......
What I knew already was that this has to be done client-side: you can't - 
yep, some ajax post hooked up to the unload event could tell you that, but 
the moment you know your user "escaped" without saving is already too late, 
the page is in the process of being refreshed to the new one.

However, you can "save" the initial form data with serialize() to a 
variable and hook up an onchange on every input to recalculate if something 
in the form is changed and raise a notification

var allinputs = $('#myform').find(':inputs')
var originaldata = allinputs.serialize()
inputs.on('change', function() {
                if (inputs.serialize() != original_data) {
                    ....raise notification , such as "Remember to save the 
data"
                }
})



There is another method - hooking up to the beforeunload event - but:
- is flaky as support in all browsers
- generally ugly, because it's styled as an alert box 
- not customizable at all
- kinda a PITA at the user interaction point of view

For the sake of completeness, here's how to activate 
    $(window).bind('beforeunload', function(){
        return "Do you really want to leave now?";
        });


will present an alert, if the user presses "Cancel" the user stays into the 
page
and how to "disable the alert"
$(window).unbind("beforeunload");




On Sunday, December 9, 2012 5:51:14 PM UTC+1, Joe Barnhart wrote:
>
>
> I've been investigating the use of the DAL feature 
> "detect_record_change=True".  Apparently it was conceived as a way of 
> detecting when the record in the database has changed since the form was 
> originally built and populated.  My need is for a way to detect when the 
> USER has changed fields in the record between the time it was built and 
> some other event, such as when the user tries to navigate away from the 
> form without pressing the "submit" button.
>
> It seems to me the idea is quite similar -- I want to serialize the data 
> in the form and then compare that hash to the same form later.  Only 
> instead of comparing the data in the database to the hash I want to compare 
> the form's version of the data again.  Has anyone already done this?  Is 
> there a better way to detect when a form has actually been changed instead 
> of just viewed?
>
> -- Joe B.
>

-- 



Reply via email to