Unique Repeater Values

  • 25 November 2015
  • 33 replies
  • 15 views

Badge +3

Hello,

 

Been building a repeater for taking in multiple issue items for my company.  Ran into a problem that I need one of the fields to be unique for each section of the repeater.  Anybody have any direction on how to do this?


Ben.


33 replies

Badge +5

Is this for Nintex on-Prem 2013/2016 or O365?

Badge +2

O365...

Already started to give up on this sad.png

Badge +5

NWF$(".testLU option:selected")[i].innerHTML should give you the selected value of the lookup list

testLU is the css class name of my look up control and i is the ith item in your repeating section.

221324_pastedImage_1.png

Badge +2

Thank you Thomas for you reply. 

I've tried your advice and it worked. I was able to get the value of the selected lookup field if I put direct index like array[0] instead of array, but if I try to loop something doesn't work. This is my JS script. I hope you can help me, could be a stupid error, just cannot find it.

   NWF$(document).ready(function(){
NWF$(".LookupFieldCss").change(function() {EnsureUniqueValue()});
});
function EnsureUniqueValue(){
 var duplicateValueFound=false;
 var rpArray= NWF$(".LookupFieldCss ");
 var rpArrayValues=[];
 for(var i=0;i<rpArray.length;i++){
  if(NWF$(".LookupFieldCss option:selected").innerHTML!="Please select a value..."){
   alert((NWF$(".LookupFieldCss option:selected").innerHTML);
   rpArrayValues.push(NWF$(".LookupFieldCss option:selected").innerHTML);
  } 
 }
 var sortedRpArrayValues=rpArrayValues.sort();
 alert(sortedRpArrayValues.length);
    for (var i = 0; i < sortedRpArrayValues.length - 1; i++){
  if (sortedRpArrayValues[i + 1] == sortedRpArrayValues){
   alert("duplicate values not allowed: "+sortedRpArrayValues);
   duplicateValueFound=true;
  }
    }
 if(duplicateValueFound){
  NWF$(".nf-repeater-addrow").hide();
 }
 else{
  NWF$(".nf-repeater-addrow").show();
 }
}
Badge +5

From memory repeatingSection first value actually starts from index 1 rather than 0 .So if you have three entered value then it would be index 1,2,3

Insert the line “debugger; “ in your code to enforce a breakpoint and use F12 developer tool to examine the values that your JavaScript code evaluates . This will give you a good idea what is happening at runtime.

Badge +2

I've got it working somehow when trying to create a new form

But sad.png , If I try to edit the same form later lookup values are not loading in edit mode, working fine in preview mode.

Preview mode

Edit mode

Script i'm using    NWF$(document).ready(function(){
NWF$(".LocalsubContractorLookupFieldCss").change(function() {EnsureUniqueValue()});
});

function EnsureUniqueValue(){       
    if(typeof NWF$(".LocalsubContractorLookupFieldCss option:selected")[1]  !== 'undefined'){
        var duplicateValueFound=false;
        var rpArray= NWF$(".LocalsubContractorLookupFieldCss");
        var rpArrayValues=[];
        for(var i=1;i<rpArray.length;i++){
           rpArrayValues.push(NWF$(".LocalsubContractorLookupFieldCss option:selected").innerHTML);
        }
        var sortedRpArrayValues=rpArrayValues.sort();
        for (var i = 0; i < sortedRpArrayValues.length - 1; i++){
            if (sortedRpArrayValues[i + 1] == sortedRpArrayValues){
                alert("duplicate values not allowed: "+sortedRpArrayValues);
                duplicateValueFound=true;
            }
        }
        if(duplicateValueFound){
            NWF$(".nf-repeater-addrow ").hide();
        }
        else{
            NWF$(".nf-repeater-addrow ").show();
        }
    }
}

The error i'm getting in F12 mode . I'm not even sure what is wrong, i'm checking it not to be 'undefined', if yes just skip. But looks like is something else

Any clues guys? 

Badge +2

The error

Badge +2

Some how finally I made it to work. The JS script that works for me. 

   NWF$(document).ready(function(){
NWF$(".LocalsubContractorLookupFieldCss").change(function() {EnsureUniqueValue()});
});


function EnsureUniqueValue(){     
    var duplicateValueFound=false;
    var rpArray= NWF$(".LocalsubContractorLookupFieldCss");
    var rpArrayValues=[];
    for(var i=1;i<rpArray.length;i++){
if(typeof NWF$(".LocalsubContractorLookupFieldCss option:selected")  !== 'undefined'){
rpArrayValues.push(NWF$(".LocalsubContractorLookupFieldCss option:selected").innerHTML);
}
    }
    var sortedRpArrayValues=rpArrayValues.sort();
    for (var i = 0; i < sortedRpArrayValues.length - 1; i++){
        if (sortedRpArrayValues[i + 1] == sortedRpArrayValues){
            alert("duplicate values not allowed: "+sortedRpArrayValues);
            duplicateValueFound=true;
        }
    }
    if(duplicateValueFound){
        NWF$(".nf-repeater-addrow ").hide();
    }
    else{
        NWF$(".nf-repeater-addrow ").show();
    }
}

Reply