5 Replies Latest reply: Jul 19, 2013 6:30 AM by Tom Petrus RSS

    save before exit ------ please help

    ReemaPuri

      http://apex.oracle.com/pls/otn/f?p=31517:258:19782275171388:::::

       

       

       

      the condition different here is my region is on page 0 and i am writing this code on page 5

       

       

      my submit button is on page 0 and i want this code only  for page 0 items but this code is affecting all items of page 5

       

       

      is there anyway to restrict for page 0 items (for eg on change of select list of page 0)

       

      my insert process is on page1

        • 1. Re: save before exit ------ please help
          vdsadhi

          Can you please explain in detail to understand your requirement??? What is the code you used on page 5???  What are the conditions you used for items on page 0??

           

          Please read about Page Zero Displaying Components on Every Page of an Application

           

          Thanks

          Lakshmi

          • 2. Re: save before exit ------ please help
            ReemaPuri

            yes

            i put code in html header on page 5 as

             

             

             

            <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[i].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="The changes you made to the page were not saved.";

             

            function WarnSave()

            {

            var formChanged=isFormChanged();

            if (!g_saving && formChanged) return g_errmsg;

            }

             

            function doSave()

            {

            g_saving=true;

            doSubmit('SUBMIT');

            }

            </script>

             

             

            and

             

             

            onBeforeUnload="return WarnSave();"

             

             

             

            and my region on which select list is P0_X AND P0_SUBMIT BUTTON

             

            IN P0_SUBMIT BUTTON THE BUTTON attribute   onclick="doSave();"

             

            so the requirement is whenever i change select list value on page 0 and without saving it should not leave page

             

            but when i change anything on page 5 the javascript should not show msgs as this functions should only be for region coming from page 0

            • 3. Re: save before exit ------ please help
              Tom Petrus

              Items from page zero are simply included in the form that is generated on page 5. It's only logical that when you use documet.wwv_flow.elements that you get all elements present in the form.

              You will need to limit the items in the "ele" array. If your items from page 0 are in a separate region you can give that region a static id and then select the items in there, but mind that this does not have an 'elements' array. You will need to select all input/textarea/select items within the region context. Why not use jQuery? It'll be easier.

              And why does "isElementChanged" need the array and the index? You use ele[i] the entire time, why don't you just pass the element in? And give your parameter a nice name too while we're at it, like you did for your variables.

              • 4. Re: save before exit ------ please help
                ReemaPuri

                can you just give me a example  to pass id p0_x

                • 5. Re: save before exit ------ please help
                  Tom Petrus

                  If all your page zero items start with P0 you can use jQuery to target them. In the code below I changed your loop mechanism to work with jQuery's each function. I changed the second function's parameter to just take the html element and not the array and index.

                   

                  function isFormChanged() {
                  var rtnVal = false;
                  $("[id^='P0_']").each(function(){
                     if(isElementChanged(this)){
                        rtnVal = true;
                        return false;
                     };
                  });
                  return rtnVal;
                  }
                  
                  
                  function isElementChanged( pElement ) {
                  var isEleChanged = false;
                  
                  switch ( pElement.type ) {
                  
                    case "text" :
                     if ( pElement.value != pElement.defaultValue ) return true;
                    break;
                  
                    case "textarea" :
                     if ( pElement.value != pElement.defaultValue ) return true;
                    break;
                  
                    case "radio" :
                     val = "";
                     if ( pElement.checked != pElement.defaultChecked ) return true;
                    break;
                  
                    case "select-one" :
                    if     (pElement.id>99 ) return false;
                     for ( var x =0 ; x <pElement.length; x++ ) {
                  if ( pElement.options[ x ].selected
                      != pElement.options[ x ].defaultSelected ) return true;
                     }
                    break;
                  
                    case "select-multiple" :
                    if     (pElement.id>99 ) return false;
                     for ( var x =0 ; x <pElement.length; x++ ) {
                  if ( pElement.options[ x ].selected !=
                      pElement.options[ x ].defaultSelected ) return true;
                     }
                    break;
                  
                    case "checkbox" :
                     if ( pElement.checked != pElement.defaultChecked ) return true;
                  
                    default:
                     return false;
                    break;
                  }
                  }   
                  
                  var g_saving = false;
                  var g_errmsg="The changes you made to the page were not saved.";
                  
                  function WarnSave()
                  {
                  var formChanged=isFormChanged();
                  if (!g_saving && formChanged) return g_errmsg;
                  }
                  
                  function doSave()
                  {
                  g_saving=true;
                  doSubmit('SUBMIT');
                  }