AnsweredAssumed Answered

How to retrieve selected items in List Lookup Control inside a Repeated Section

Question asked by karlsanada13 on Aug 31, 2018

Good day!

 

I have here a List Lookup Control inside a repeated section. I use it for getting items and users have to input the resources/person/notes in the textbox with resources label. I've used a different approach before and know how to get a value from a List Lookup with List view, but not on the default view.

 

 

My question is:

 

I would like to have a validation on add button: How can I an event when it is clicked?

 

NWF.FormFiller.Events.RegisterAfterReady(function ()
{
   let initialString;
   NWF$(".addItemLabelButton").click(function()
   {
     let row = NWF$(this).closest('.nf-repeater-row');
    let selectedItems = row.find('.calculatedSelectionCSS label').text();
     initialString = row.find('.classText textarea').val();
     let arrayItems;
     let result = selectedItems.slice(1,-1);
     let newString = "";
     arrayItems = result.split(',');
     let duplicatedItems = "";
     let hasDuplicate = 0;
     for(let i = 0; i < arrayItems.length; i++){
          let itemString = arrayItems[i].split(" -");
          let isDuplicate = 0;
          NWF$('.vtMyRepeatingSection .nf-repeater-row:not(.nf-repeater-row-hidden)').each(function (){
          let $row = NWF$(this);
          let $textLine=$row.find('.classText textarea').val();
          let multilineText = $textLine.split('\n'); 
          for (let j = 0; j < multilineText.length; j++){
               if (itemString[0].trim() == multilineText[j]){
               isDuplicate = 1;
               hasDuplicate = 1;
               duplicatedItems = duplicatedItems + itemString[0].trim() + "\n";
               break;
               }

               if (isDuplicate == 1){
               break;
               }
               }

          });
     if (isDuplicate == 0){
     newString = newString + itemString[0].trim();
          if (i != arrayItems.length - 1){
          newString = newString + "\n"; 
          }
     }
     }
     if (initialString === ""){
     }
     else{
     initialString = initialString + "\n";
     }
     if (hasDuplicate === 1 && selectedItems != ""){
      alert(duplicatedItems + " are already included in a row. Please remove these in the selection");
     } 
     else if (selectedItems != ""){
     initialString = initialString.concat(newString);
     row.find('.classText textarea').val(initialString);
     }
     row.find('.listLookUpCSS option:selected').prop('selected', false);
     row.find('.calculatedSelectionCSS label').text("");
     });

});

I used to have this code where I transfer the selected items with a label button and transfer it to a multi-line textbox. Not knowingly that List Lookup has an OOTB function with add/remove buttons already.

 

So TLDR: I want to have an event when add item is clicked, just to check duplicates, and is it possible to cancel the ootb function when it does have a duplicate on other rows?

Outcomes