Author Topic: Key/Value Pair Validation  (Read 7171 times)

Benjamin Dasari

  • GuiXT Forum
  • Newbie
  • *
  • Posts: 96
    • View Profile
Key/Value Pair Validation
« on: July 25, 2016, 05:01:38 PM »
Purpose:
Perform data validation using key value pair logic.

Liquid UI Code:

// SAPLSMTR_NAVIGATION.E0100.sjs

// Data Validation Array in Key/value pairs
var requiredDataArr = [{key:'Material',value:z_material},
                  {key:'Vendor',value:z_vendor},
                  {key:'Division',value:z_division},
                  {key:'EAN Category',value:z_ean_cat},
                  {key:'Season',value:z_season}];   

// Function to trim blank spaces at the end of the string
String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,'');}
                     
// Function to check if the string value is blank
function isBlank(jvar){
   if(typeof jvar == 'string') {
      jvar = jvar.trim();
   }
   if(typeof jvar == 'undefined') {
      jvar = '';
   }
   return(jvar == 'undefined' || jvar == undefined || jvar == null || jvar == "" || jvar == void 0);
}

// Function is used to check if value is blank for a any key in the array
// If value is blank, then returns the key associated with the blank value
function isBlankKeyValue(arr){
   for(i=0;i<arr.length;i++){
      if(isBlank(arr[ i].value)){
         return arr[ i].key;
      }   
   }   
   return null;   
}

// Function to validate required fields                     
function validateRequiredData(){
   var validateReqData = isBlankKeyValue(requiredDataArr);
   if(!isBlank(validateReqData)){
      message('E: '+validateReqData+ ' is required field');
      goto SCRIPT_END;
   }      
   message('S: Validation successful');
   SCRIPT_END:;   
}

// User Interface
clearscreen();
inputfield([1,0], "Material", [1,25], {"size":10, "name":"z_material", "required":true});
inputfield([2,0], "Vendor", [2,25], {"size":10, "name":"z_vendor", "required":true});
inputfield([3,0], "Division", [3,25], {"size":2, "name":"z_division", "required":true});
inputfield([4,0], "EAN Category", [4,25], {"size":2, "name":"z_ean_cat", "required":true});
inputfield([5,0], "Season", [5,25], {"size":2, "name":"z_season", "required":true});
pushbutton([7,7],"@01@Read Data", "?", {"process":validateRequiredData});


See attachments for code samples!
« Last Edit: July 28, 2016, 02:49:13 PM by Benjamin Dasari »