Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Grace Green
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I remember the code should look something like



Is that how you are registering the widget?

Eric
 
Grace Green
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to add the class cancelsUnsavedChangesWarning to the button that submits your form.

Eric
 
Grace Green
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I modified the submit function by adding the line in bold , but that still does not work ...

 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You want to set window.cancelUnsavedChangesWarning = true; in your submit function.

Eric

 
Grace Green
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tried with lots of hopes, but it did not work. Same problem.

 
Grace Green
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Solved: teh unsavedChangesWarningField had to belong to ignore-changes class.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic