Skip to Main Content

APEX

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Save before exit

skahlertSep 12 2010 — edited Dec 10 2010
Dear apex devs,

I integrated Denes' example in my app to warn users to save changes before exiting the modified page.

I modified the button template to match my own requirements and am calling a custom jquery function in the doSave function of Denes' example.

The bug or problem I encountered is that the script even alerts if no changes have been made. I am using Apex v.3.1 and was wondering if anybody here has a clue as to why changes are detected although none have been made. Could it be due to the binding of page items via page processes?

The script is as follows:
<script type="text/javascript">

function isFormChanged() {
 var rtnVal = false; 
 var frm = document.wwv_flow;
 var ele = frm.elements;

 for ( i=0; i < ele.length; i++ ) {
  if ( ele.type.length > 0 ) {
if ( isElementChanged( ele, i ) ) {
rtnVal = true;
break;
}
}
}
return rtnVal;
}

function isElementChanged( ele, i ) {
var isEleChanged = false;

switch ( ele[i].type ) {

case "text" :
if ( ele[i].value != ele[i].defaultValue ) return true;
break;

case "textarea" :
if ( ele[i].value != ele[i].defaultValue ) return true;
break;

case "radio" :
val = "";
if ( ele[i].checked != ele[i].defaultChecked ) return true;
break;

case "select-one" :
if (ele[i].id>99 ) return false;
for ( var x =0 ; x <ele[i].length; x++ ) {
if ( ele[i].options[ x ].selected
!= ele[i].options[ x ].defaultSelected ) return true;
}
break;

case "select-multiple" :
if (ele[i].id>99 ) return false;
for ( var x =0 ; x <ele[i].length; x++ ) {
if ( ele[i].options[ x ].selected !=
ele[i].options[ x ].defaultSelected ) return true;
}
break;

case "checkbox" :
if ( ele[i].checked != ele[i].defaultChecked ) return true;

default:
return false;
break;
}
}

var g_saving = false;
var g_errmsg="Attention! Do you want to leave without saving?";

function WarnSave()
{
var formChanged=isFormChanged();
if (!g_saving && formChanged) return g_errmsg;
}

function doSave()
{
g_saving=true;
warning2();void 0;

}
</script>
Many thanks for any ideas that you might have!

Brgds,

Seb

Edited by: skahlert on 12.09.2010 15:03                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
This post has been answered by jariola on Sep 12 2010
Jump to Answer

Comments

jariola
Hi,

Might help
http://www.aspdeveloper.net/tiki-index.php?page=HTMLTipsCheckIfFormDirty

Regards,
Jari

Edited by: jarola on Sep 12, 2010 5:08 PM

And if you check Apex javascript source code there is function htmldb_item_change that might help
skahlert
Thanks Jari! I will have a look at it!

Brgds,

Seb
jariola
Answer
Hi,

Here is another way to do it. Place to page HTML header
<script type="text/javascript">
$(function(){
 $('#wwvFlowForm').data('htmldb',{'dirty':false});
 $(':input:not(:hidden,:submit,:password,:button)').live('change',function(){
   $('#wwvFlowForm').data('htmldb',{'dirty':true})
 });
 $(window).bind('beforeunload',function(){
  if($('#wwvFlowForm').data('htmldb').dirty){return "The changes you made to the page were not saved."}
 });

/* Change this according your form submit button */ 
 $('input:button[value="Submit"]').unbind('click').removeAttr('onclick').click(function(){
  $('#wwvFlowForm').data('htmldb',{'dirty':false});javascript:apex.submit('SUBMIT')
 });
});
</script>
Sample here
http://apex.oracle.com/pls/otn/f?p=40323:65



Regards,
Jari
Marked as Answer by skahlert · Sep 27 2020
skahlert
Good morning Jari!

Well what should I say?! I started to run the crucial page this morning and all the sudden everything works properly as it should!
No alerts on false occasions whatsoever! I'd like to thank you for your help and omnipresent ideas! Great job!

Have a successful start into this week!

Brgds,

Seb
soliphant
All,

I'm attempting to do the same thing, using the script shown. Everything is working except when I exit the page without saving, I get the warning message and when I click OK, I get the message again. Click OK and then it exists. Any ideas why I get the message twice? There are no other submits on the page. I'm stumped and desperate:

Sandie

Using 3.2.1
Violeta
Hi Jari,
I applied your script to the HTML Header of my page but the problem is that I am even getting the message when I try to save the page. Could you please let me know what changes I need to apply to avoid that the warning message is display when the user push my SAVE button?

-----------------------------------------------
<script type="text/javascript">
$(function(){
$('#wwvFlowForm').data('htmldb',{'dirty':false});
$(':input:not(:hidden,:submit,:password,:button)').live('change',function(){
$('#wwvFlowForm').data('htmldb',{'dirty':true})
});
$(window).bind('beforeunload',function(){
if($('#wwvFlowForm').data('htmldb').dirty){return "The changes you made to the page were not saved."}
});

/* Change this according your form submit button */
$('input:button[value="Submit"]').unbind('click').removeAttr('onclick').click(function(){
$('#wwvFlowForm').data('htmldb',{'dirty':false});javascript:apex.submit('SUBMIT')
});
});
</script>
------------------------------------------
Thanks,
Violeta
MilesTeg
I am also having this problem. I have tried every variation I can think of for this code without any luck. Oracle XE, apex 3.1.2. The save button always causes the prompt as well.

/* Change this according your form submit button */
$('input:button[value="Submit"]').unbind('click').removeAttr('onclick').click(function(){
$('#wwvFlowForm').data('htmldb',{'dirty':false});javascript:apex.submit('SUBMIT')
});

Thanks
MilesTeg
Edited by: MilesTeg on Dec 7, 2010 4:20 PM

Edited by: MilesTeg on Dec 7, 2010 4:21 PM
user3167441
Jari,
I'm experiencing the same problem in APEX 4.0. Did you resolve this issue? If so, would you mind sharing?
Thanks.
Suzi
1 - 8
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jan 7 2011
Added on Sep 12 2010
8 comments
2,008 views