Friday, May 18, 2018

Java script file Copy field from previous field

create this javascript file under ViewController

/*F9 lov function*/
function showMyLOV(event) {
  var source = AdfPage.PAGE.getActiveComponent();
  if (event.getKeyCode() == AdfKeyStroke.F9_KEY) {
      if (source.getTypeName() == "AdfRichInputListOfValues") {
            AdfLaunchPopupEvent.queue(source, true);
            src = event.getSource();
            //AdfDhtmlInputListOfValuesPeer.FocusNextElement(popId);
            //event.cancel();
      }else if(source.getTypeName() == "AdfRichInputDate"){
        src = event.getSource();
        var subId = AdfRichUIPeer.CreateSubId(src.getClientId(), AdfDhtmlInputDatePeer._POPUP_ID);
        var b1ComponentRef = AdfPage.PAGE.findComponentByAbsoluteId(subId);
        hints = {alignId:src.getClientId(), align:AdfRichPopup.ALIGN_END_BEFORE};
        b1ComponentRef.show(hints);
        event.cancel();
      }
    }
}


/**
 * Copy field from previous field
 */

 function copyPrevious(event){
    keyCode = event.getKeyCode();
    var curItem = event.getSource();
 
if (keyCode == AdfKeyStroke.F8_KEY){
 
     var ac = AdfPage.PAGE.getActiveComponent();
 
     var parent = ac.getParent();
   
            while (parent)  {
              if (parent instanceof AdfRichTable) {
                  break;
              }
               parent = parent.getParent();
             }
   
     if (parent instanceof AdfRichTable) {
       
          //using a matcher to split up the clientId so we can calculate the new clientId we want to navigate to
          var clientId = ac.getClientId().match("(.*):([0-9]+)(:[^:]+)");
          var newRowKey
          var tablePeer  = parent.getPeer();
          tablePeer.bind(parent);
          newRowKey1 = tablePeer._getPreviousRowKeyAndRow(clientId[2]).rowKey;
          newRowKey = tablePeer._getNextRowKeyAndRow(clientId[2]).rowKey;
       
          //nextSibling
          var id = clientId[1]+":"+newRowKey1+":"+curItem.getId();
          var copyItem = AdfPage.PAGE.findComponentByAbsoluteId(id);
          //alert(clientId[1]+" --- "+clientId[2]+" "+newRowKey+" "+newRowKey1+" "+id+" "+copyItem+" "+curItem);

  if(copyItem!=null){
  var value = copyItem.getValue();
  curItem.setValue(value);
  }else{
                    alert('Nothing to copy'+id);
                   }

          //event.cancel();
        }
    }
}


we need drop client listener where ever we want

<af:clientListener method="copyPrevious" type="keyDown"/>




===================
How to move to first attribute when I reaches to last attribute
===================
function navigateToFirstField(evt) {
          keyCode = evt.getKeyCode();
          if (keyCode == AdfKeyStroke.TAB_KEY) {
              //alert('Enterde into JS Code');
              var lastField = evt.getSource();
              var firstField = lastField.findComponent("prodCodeId");
              firstField.focus();
              evt.cancel();
          }
      }
=======================

No comments:

Post a Comment