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!

is it possible that my dynamic actions are cancelling each other out?

KarenHAug 1 2013 — edited Aug 2 2013

Hi Everyone,

I am trying to simplify my apex 4.2 code with dynamic actions.   I have a tabular form based on a collection.   The tabular forms contains (among many variables) the following:

SELECT
apex_item.text(1,seq_id,'','','id="f01_'||seq_id,'','') "DeleteRow",
seq_id,
seq_id display_seq_id,
...

apex_item.text(10,TO_NUMBER(c010),5,null, null,'f10_'||seq_id,'') Quantity,
apex_item.text(11,TO_NUMBER(c011),5,null,null, 'f11_'||seq_id,'') Price,

apex_item.text(12, TO_NUMBER(c012),5,null,null,'f12_'||seq_id,'') Dollars

from apex_collections where....

  • when quantity is changed, recalculate total dollars as quantity*price
  • when price is changed, check price boundaries,  recalculate total dollars as quantity*price
  • when dollars changed, recalculate price as quantity/total dollars.
  • when total dollars is changed, recalculate the GRAND TOTAL

I have created a separate Dynamic Action for QUANTITY, PRICE, and DOLLARS....and then another DYNAMIC ACTION which fires when any value in the tabular form changes and writes it to the collection.   When PRICE or DOLLARS changes, everything appears to work properly....if PRICE changes, DOLLARS is recalculated.  If DOLLARS changes, PRICE is recalculated.   I am having a problem with QUANTITY though.  It appears for a split instance that when QUANTITY changes, DOLLARS changes...but only for a moment, and then it goes back to the previous value.  I am wondering if these dynamic actions are canceling each other out?

dynamic action on QUANTITY

event: CHANGE

selection type: JQUERY SELECTOR

jquery: input[name='f10']

true action1- execute javascript code:

var lSeq = $(this.triggeringElement).closest("tr").find("input[name='f01']").val();

setTotal(lSeq);

dynamic action on PRICE

event: CHANGE

selection type: JQUERY SELECTOR

jquery: input[name='f11']

true action1- execute javascript code:

var lSeq = $(this.triggeringElement).closest("tr").find("input[name='f01']").val(); 

getPriceBoundaries(lSeq);

dynamic action on DOLLARS

event: CHANGE

selection type: JQUERY SELECTOR

jquery: input[name='f12']

true action1- execute javascript code:

var lSeq = $(this.triggeringElement).closest("tr").find("input[name='f01']").val(); 

selectDollarsFocus(lSeq, this.browserEvent); 

changePrice(lSeq);

dynamic action: column change  (for any column in the tabular form)

event:  CHANGE

selection type: JQUERY SELECTOR

jquery: input[name='f10'],input[name='f11'],input[name='f12'], .shark_info, .hms_info

true action 1: set value javascript expression, p110_id = this.triggeringElement.id

true action 2: set value javascript expression, p110_value = this.triggeringElement.value

true action 3: set value pl/sql, p110_seq = rtrim(substr(:P110_ID,5,4),'0')

true action 3: execute pl/sql

declare 

  v_attr number; 

begin  
  v_attr := TO_NUMBER (SUBSTR (:P110_id, 2, 2)); 
  safis_collections.update_column( :P110_SEQ, 
                                   v_attr, 
                                   :P110_VALUE); 
end;

true action 4:  refresh region landings

finally, the javascript functions are:

<script language="JavaScript1.1" type="text/javascript">

function setTotal(row)
{
   //quantity was entered into form, get values
   var price = $x('f11_'+row);
   var total = $x('f12_'+row);
   var quantity = $x('f10_'+row);
   var nquantity = parseFloat(quantity.value);
   var ntotal;
   var nprice;
   nquantity = nquantity.toFixed(3);
   quantity.value = nquantity;
   //if quantity and price both have values calculate total and save
   if(quantity.value > 0 && price.value > 0)
   {
      ntotal = quantity.value * price.value;
      total.value = ntotal.toFixed(2);
   }
   else
   {
         //if quantity and total both have values calculate price and save
      if(quantity.value > 0 && total.value > 0)
      {
         nprice = total.value/quantity.value;
         price.value = nprice.toFixed(6);
         //check to see if the price entered falls within min/max for that species
         var get = new htmldb_Get(null,&APP_ID.,'APPLICATION_PROCESS=PriceBoard',0);
         get.add('SPECIESPRICE',price.value);
         get.add('SEQUENCEID',row);
         gReturn = get.get();
         if ((gReturn == 'Price entered is too high') || (gReturn == 'Price entered is too low')){alert(gReturn);}
      }
      else  if (quantity.value > 0)
               total.value = '';
            else
            {
                 total.value = '';
                 quantity.value = '';
            }
   }

  //saveQPD(row);

   setOverallTotal();
}

function setOverallTotal()
{
   var total = 0;
   var nTotal;
   for(i=1;i<=rowCount;i++)
   {
      if(parseFloat($x('f12_'+i).value) > 0)
      {
         total = total + parseFloat($x('f12_'+i).value);
      }
   }
   ntotal = total.toFixed(2);
   document.getElementById("P3_TOTAL").value = ntotal;
   var get = new htmldb_Get(null,&APP_ID.,'APPLICATION_PROCESS=nullProcess',0);
   get.add('P3_TOTAL',ntotal);
   gReturn = get.get();
}

function getPriceBoundaries(row)
{
   //price was entered into form get all values
   var quantity = $x('f10_'+row);
   var price = $x('f11_'+row);
   var total = $x('f12_'+row);
   var ntotal;
   var nquantity;
   var nprice = parseFloat(price.value);
   nprice = nprice.toFixed(6);
   price.value = nprice;
   //check to see if the price entered falls within min/max for that species
   var get = new htmldb_Get(null,&APP_ID.,'APPLICATION_PROCESS=PriceBoard',0);
   get.add('SPECIESPRICE',price.value);
   get.add('SEQUENCEID',row);
   gReturn = get.get();
   if ((gReturn == 'Price entered is too high') || (gReturn == 'Price entered is too low')){alert(gReturn);}
   //if quantity and price both have a value calculate the total
   if(quantity.value > 0 && price.value > 0)
   {
      ntotal = quantity.value * price.value;
      total.value = ntotal.toFixed(2);
   }
   else
   {
      //if total and price both have a value calculate the quantity
      if(total.value > 0 && price.value > 0)
      {
         nquantity = total.value/price.value;
         quantity.value = nquantity.toFixed(3);
      }
      else
      {
         if(price.value > 0)
              total.value = '';
         else
         {
              total.value = '';
              price.value = '';
         }
      }
   }
   saveQPD(row);
   setOverallTotal();
}

function saveQPD(row)
{
   var quantity = $x('f10_'+row).value;
   var price = $x('f11_'+row).value;
   var total = $x('f12_'+row).value;
   //save quantity
   var get = new htmldb_Get(null,&APP_ID.,'APPLICATION_PROCESS=setQuantity',0);
   get.add('SETVALUE',quantity);
   get.add('SEQUENCEID',row);
   gReturn = get.get();
//   alert(gReturn);

   //save price
   get = new htmldb_Get(null,&APP_ID.,'APPLICATION_PROCESS=setPrice',0);
   get.add('SETVALUE',price);
   get.add('SEQUENCEID',row);
   gReturn = get.get();
//   alert(gReturn);

   //save total
   var get = new htmldb_Get(null,&APP_ID.,'APPLICATION_PROCESS=setTotal',0);
   get.add('SETVALUE',total);
   get.add('SEQUENCEID',row);
   gReturn = get.get();
//   alert(gReturn);
  
}

function changePrice(row)
{
   //total was entered get all rows
   var quantity = $x('f10_'+row);
   var price = $x('f11_'+row);
   var total = $x('f12_'+row); 
   var ntotal = parseFloat(total.value);  
   var nprice;
   var nquantity;
   ntotal = ntotal.toFixed(2);
   total.value = ntotal;
   //if quantity and total were entered calculate price.
   if (quantity.value > 0 && total.value > 0)
   {
      nprice = total.value / quantity.value;
      price.value = nprice.toFixed(6);
      var get = new htmldb_Get(null,&APP_ID.,'APPLICATION_PROCESS=PriceBoard',0);
      get.add('SPECIESPRICE',price.value);
      get.add('SEQUENCEID',row);
      gReturn = get.get();
         if ((gReturn == 'Price entered is too high') || (gReturn == 'Price entered is too low')){alert(gReturn);}
   }

   //if price and total were entered calculate quantity.
   if (price.value > 0 && total.value > 0)
   {
      nquantity = total.value / price.value; 
      quantity.value = nquantity.toFixed(3);
   }

   if (price.value > 0 && quantity.value > 0)
   {
       ntotal = quantity.value * price.value;
       total.value = ntotal.toFixed(2);
   }

      

   saveQPD(row);

   setOverallTotal();       
}


function selectDollarsFocus(pRow,event)
{
    tabPress = 0;
    KeyCheck(event);
    if($x('f11_'+ pRow))
    {
            if(KeyID == 9)
            {
                $x('f14_'+ pRow).focus();
                onFocusAreaFished(pRow);
                tabPress = 1;
            }
    }
    else
    {
        if($x('f18_'+ pRow))
        {
                if(KeyID == 9)
                {
                    $x('f18_'+ pRow).focus();
                    tabPress = 1;
                }
        }
        else
        {
            if(--pRow <= rowCount)
                if(KeyID == 9)
                {
                    $x('f08_'+ pRow).focus();
                    tabPress = 1;
                }
        }
       
    }
}

</script>

any thoughts really appreciated!  thanks

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 30 2013
Added on Aug 1 2013
5 comments
784 views