This discussion is archived
1 2 Previous Next 23 Replies Latest reply: Feb 15, 2012 11:53 PM by fac586 RSS

Save Warning process

180271 Newbie
Currently Being Moderated
I wanted to give the users a warning message if they tried to exit a page without saving. I had implemented the 'WarnSave' procedure I saw in the forum threads. It works great except for date fields. If the user hits the 'Calendar' image that show next to a date, the warning alert pops up. Any suggestions?


<script type="text/javascript">

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

}

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 && ele[i].style.backgroundColor == "yellow" ) return true;
break;
}
}     

var g_saving = false;
var g_errmsg="There are unsaved changes on this page.";
g_errmsg += "\n- To save your changes, click the Cancel button, and then click on the Submit button.";
g_errmsg += "\n- To disregard your changes, click on the OK button.";

function doSave()
{
g_saving=true;
doSubmit('SAVE');
}
function doCreate()
{  
g_saving=true;
doSubmit('CREATE');
}
function doCancel()
{  
g_saving=false;
doSubmit('CANCEL');
}
</script>
  • 1. Re: Save Warning process
    dmcghan Oracle ACE
    Currently Being Moderated
    Bob,

    I can't get this code working in FireFox or IE. Does it work with select lists? Also, when are you calling WarnSave()?

    Regards,
    Dan

    http://danielmcghan.us
    http://sourceforge.net/projects/tapigen
  • 2. Re: Save Warning process
    180271 Newbie
    Currently Being Moderated
    In the HTML Body Attribute of the Page.

    onBeforeUnload="return WarnSave();"
  • 3. Re: Save Warning process
    dmcghan Oracle ACE
    Currently Being Moderated
    Bob,

    That is the correct place to make the call. I was a little worried you might have been calling it via a click event on a button. Are you able to post an example of this on apex.oracle.com? It doesn't have to be your exact application, just a mock up for a test would be great.

    Regards,
    Dan

    http://danielmcghan.us
    http://sourceforge.net/projects/tapigen
  • 4. Re: Save Warning process
    180271 Newbie
    Currently Being Moderated
    Ok. I'll put something om apex. I saw some threads about replacing the datepicker with JQUERY and that the next version of APEX will be using JQERY. Any truth to this?
  • 5. Re: Save Warning process
    dmcghan Oracle ACE
    Currently Being Moderated
    Bob,

    Great, let me know when it's up. Also, I'll need some credentials. As for jQuery, I too have heard that it will be included with a future release. I don't want to speculate, however, as to when. But adding jQuery is such an easy thing to do I wouldn't wait to make this change. In fact, I was planning to look at your example and make a newer version with jQuery code. The reason being that there are many different item types in an ApEx application and I don't know if that code is the best way to go. It should be fun to rewrite in jQuery.

    Regards,
    Dan

    http://danielmcghan.us
    http://sourceforge.net/projects/tapigen
  • 6. Re: Save Warning process
    180271 Newbie
    Currently Being Moderated
    Dan,

    Here is the link:
    http://apex.oracle.com/pls/otn/f?p=12563:3:2591715139492529:::::

    On the report, click the pencil to edit (brings you to form). Changing any field, will turn the field yellow. If you attempt to 'Cancel' or close window without saving, it will give you warning alert (as it should). The problem is if you change a field and then click on the calendar image, it also gives you a warning (because the pop-up is coming up). I don't want the warning message to come up when users hit the calendar image.

    Thanks!
  • 7. Re: Save Warning process
    180271 Newbie
    Currently Being Moderated
    1 other things. Some of the code is on Page 0 (Region Source of 'HTML Javascript' region).
  • 8. Re: Save Warning process
    dmcghan Oracle ACE
    Currently Being Moderated
    Bob,

    Could you please provided credentials to access the application? You could always create an account for now and lock it back down later.

    Regards,
    Dan

    http://danielmcghan.us
    http://sourceforge.net/projects/tapigen
  • 9. Re: Save Warning process
    180271 Newbie
    Currently Being Moderated
    I made the application without credentials needed. Are you being asked for login info?
  • 10. Re: Save Warning process
    dmcghan Oracle ACE
    Currently Being Moderated
    Bob,

    Yes, that's correct.

    Regards,
    Dan

    http://danielmcghan.us
    http://sourceforge.net/projects/tapigen
  • 11. Re: Save Warning process
    180271 Newbie
    Currently Being Moderated
    I created user: TEST password: TEST

    Workspace: CENTURY
  • 12. Re: Save Warning process
    dmcghan Oracle ACE
    Currently Being Moderated
    Bob,

    Perfect. I'm getting killed right now with "real work" but I will make sure to look into this tonight and let you know what I find ASAP.

    Regards,
    Dan

    http://danielmcghan.us
    http://sourceforge.net/projects/tapigen
  • 13. Re: Save Warning process
    dmcghan Oracle ACE
    Currently Being Moderated
    Bob,

    You said...
    If the user hits the 'Calendar' image that show next to a date, the warning alert pops up.
    I'm not getting that at all. I've tested in both FireFox and IE8 and it seems to be working fine. Only if I select a different date from the popup does it turn the background yellow and warn me if I try to leave without saving.

    That being said, I'm going to keep looking into this as I want to rewrite it in jQuery and make it work with more item types. It failed on the select list...

    Regards,
    Dan

    http://danielmcghan.us
    http://sourceforge.net/projects/tapigen
  • 14. Re: Save Warning process
    438381 Guru
    Currently Being Moderated
    The behaviour described by Bob is seen with IE 7 (my browser). MSDN has a possible explanation for the observed quirkiness

    Scroll down to the 'Community Content' section at http://msdn.microsoft.com/en-us/library/ms536907(VS.85).aspx


    Varad
1 2 Previous Next

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points