File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes jquery -- code review comparing original and current values on a form Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "jquery -- code review comparing original and current values on a form" Watch "jquery -- code review comparing original and current values on a form" New topic
Author

jquery -- code review comparing original and current values on a form

Grace Green
Ranch Hand

Joined: Nov 08, 2010
Posts: 72
I am new to JQuery and I am using a Jquery plugin. THe code below is from the plugin.
_areValuesEqual takes the original values of the document form (a) and compares them to the current values (b). Only the first alert gets executed. So, the code flow never gets inside the loops.

_areValuesEqual gets called inside the function hasChanges, which I copy below.

Any help on how to debug this would be highly appreciated.

Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
If I remember the code should look something like



Is that how you are registering the widget?

Eric
Grace Green
Ranch Hand

Joined: Nov 08, 2010
Posts: 72
Yes, indeed.
My problem is that even after the document form changes are saved correctly, myForm.fieldvaluewatcher('hasChanges') evaluates to true, and the onbeforeunload executes ...

# if ( myForm.fieldvaluewatcher('hasChanges') ) {
# return "There are unsaved changes!";
# }

Grace Green
Ranch Hand

Joined: Nov 08, 2010
Posts: 72
Here is the onbeforeunload the author of the plugin suggests to use.
It is not clear to me what window.cancelUnsavedChangesWarning is and how in the documents it gets set; no mention of how to set up
$('.cancelsUnsavedChangesWarning') ...

Anyone would be able to help ?

Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
You have to add the class cancelsUnsavedChangesWarning to the button that submits your form.

Eric
Grace Green
Ranch Hand

Joined: Nov 08, 2010
Posts: 72
I did add the class to the submit button, but after the form is submitted, the onbeforeunload still fires its warning ...
Grace Green
Ranch Hand

Joined: Nov 08, 2010
Posts: 72
I think the problem is that I have not figured out a way to make the plugin accept the changes, so that after the submit, the new values on the form are now those against which new changes have to be compared.



Grace Green
Ranch Hand

Joined: Nov 08, 2010
Posts: 72
I modified the submit function by adding the line in bold , but that still does not work ...

Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
You want to set window.cancelUnsavedChangesWarning = true; in your submit function.

Eric

Grace Green
Ranch Hand

Joined: Nov 08, 2010
Posts: 72
Tried with lots of hopes, but it did not work. Same problem.

Grace Green
Ranch Hand

Joined: Nov 08, 2010
Posts: 72
the difference between the original values and the current values is that the hidden field "unsavedChangesWarningField" is not null in the current values.
How do I set the "unsavedCHangesWarningField" to the null string ?
I thought the way I did it in the submit function was correct, but that is not the case evidently.
Grace Green
Ranch Hand

Joined: Nov 08, 2010
Posts: 72
Solved: teh unsavedChangesWarningField had to belong to ignore-changes class.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jquery -- code review comparing original and current values on a form