cancel
Showing results for 
Search instead for 
Did you mean: 
Workflow Hero

Unique Repeater Values

Jump to solution

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.

Labels: (2)
0 Kudos
Reply
33 Replies
Workflow Hero

Re: Unique Repeater Values

Jump to solution

Hi Ben,

Do you just need to number the rows? If that's it you can use a calculated value control in your repeating section and use formula currentRowNumber. See the attached link with Manfred Lauer's comment at the bottom of the page, Nintex Forms - Numbering a Repeating Section - Vadim Tabakman

Jan

0 Kudos
Reply
Workflow Hero

Re: Unique Repeater Values

Jump to solution

Thanks for the suggestion Jan.

Sadly this is nothing that simple.


The idea is that the users can enter in a brief description of an item.  That description needs to be unique for each item.  So they could do something like...

Item A - Desc 1

Item A - Desc 2

Ben.

0 Kudos
Reply
Workflow Hero

Re: Unique Repeater Values

Jump to solution

Hi Ben.

You should be able to use jquery to achieve this.

-assign a css class for the repeater control

- assign a css class for the control that needs to have unique value in the repeater control

-in your jquery code, On Repeater control change loop through the values already entered in the control and ensure they are all unique

if one value is duplicated then disable the submit button and have a onscreen error or show a error label.

Thomas

0 Kudos
Reply
Workflow Hero

Re: Unique Repeater Values

Jump to solution

Thomas,

Thanks for the reply. That makes a lot of sense and sounds exactly like I need to do. Still learning the in's and outs of Nintex and repeaters in general.  Can I get an example of what kind of code I would need?  I learn best when I can see examples and adapt them.

Ben.

0 Kudos
Reply
Workflow Hero

Re: Unique Repeater Values

Jump to solution

Hi Ben.

 

See below for my quick proof of concept.

 

Nintex Form Settings:

Custom Javascript to include:

NWF$(document).ready(function()

{

  //event will be fired every time the new repeater textbox value is entered

  NWF$(".myTextboxValue").keyup(function() {

       EnsureUniqueValue()

     });

});

 

 

 

 

function EnsureUniqueValue()

{

  var duplicateValueFound=false;

  var rpArray= NWF$(".myTextboxValue .nf-textbox-wrapper input")

  var rpArrayValues=[]

 

//Push all non-empty values from repeating section to another array

  for (var i = 0; i < rpArray.length; i++)

  {

  if(rpArray.value !="")

  {

  rpArrayValues.push(rpArray.value)

 

  }

  }

//sort the array

  var sortedRpArrayValues = rpArrayValues.sort();

 

 

//check for duplicate values in the sorted array

    for (var i = 0; i < sortedRpArrayValues.length - 1; i++)

  {

     if (sortedRpArrayValues[i + 1] == sortedRpArrayValues)

  {

        alert("duplicate values not allowed: "+sortedRpArrayValues);

  duplicateValueFound=true;

      }

    }

 

//Hide new item add link and any other buttons (eg save button) you want hidden if duplicate values are found

  if(duplicateValueFound)

  {

  NWF$(".nf-repeater-addrow").hide()

  }

  else

  {

  NWF$(".nf-repeater-addrow").show()

  }

}

 

End result:

 

 

Reply
Workflow Hero

Re: Unique Repeater Values

Jump to solution

You sir, are amazing.

Thank you so much!

0 Kudos
Reply
Workflow Hero

Re: Unique Repeater Values

Jump to solution

Hey Thomas,

I'm trying to use array.length() in one of my forms, but keep getting the error that items.length is not a valid function. I'm sure I'm missing something simple, perhaps you can assist? The relevant code looks like this:

var options = [];
function showMe() {
{
var items = NWF$('#' + multiChoices + ' :checkbox:checked');
console.log(items);
var count = items.length();

for (i = 0; i < count; i++)
{
     var currentValue = items[i];
     console.log(currentValue);

     if (currentValue.endsWith(0))
     {
     options.push(1);
     }
     else if (currentValue.endsWith(1))
     {
     options.push(2);
     }

I was doing like your example and just having for (i=0; i < items.length(); i++) and only declared the count variable to see if that helped anything. I'm in O365 if that makes a difference.

I have a question going here   and Aaron has been helping, but I didn't know if you could assist on the .length() not working.

Reply
Workflow Hero

Re: Unique Repeater Values

Jump to solution

length is a property, not function.

so until you write your own length() function you should use it without braces.

JavaScript Array length Property 

0 Kudos
Reply
Workflow Hero

Re: Unique Repeater Values

Jump to solution

I have responded to your original question

Yeah, as ‌ mentioned, .length is what you need is you want to check the length of an array. 

0 Kudos
Reply