Skip to main content
Nintex Community Menu Bar
Solved

jQuery to get value of control in last row of Repeating Section

  • January 8, 2019
  • 9 replies
  • 257 views
  • Translate

Forum|alt.badge.img+5
  • 27 replies

Using jQuery how do I get the value of a field in the last row of a repeating section:

 

 

In the screenshot above the Type fields are lookup controls with a class of .ItemType

 

I would need to return a value of "Software".

Best answer by chaddavis

My apologies. I used a Text field. I didn't realize you were using a Lookup field.


Try this code instead:

var myFields = NWF$('.myField option:selected');
var lastText = myFields[myFields.length - 1].text;
View original
Did this topic help you find an answer to your question?

9 replies

Forum|alt.badge.img+7
  • 211 replies
  • January 8, 2019

If you give the Type control a CSS class (like myField), you should be able to use this code:

var myFields = NWF$('.myField');
var lastValue = myFields[myFields.length - 1].value;

The 'lastValue' variable should have the last field's value.

Of course, you're going to need some sort of trigger, because if you run it on form load, the filed will be empty in a new form. It won't have a value until someone enters it. 

Translate

Forum|alt.badge.img+5
  • Author
  • 27 replies
  • January 8, 2019

Thanks for responding. I'm using Chrome console at the moment to test my jQuery.

Your suggestion returns 'undefined'.

My Type controls have a class of .ItemType (i've updated the original post to reflect this).

I can see that we can target the last row in the repeating section using the following code:

NWF$('.nf-repeater-row:last')...;

And I've used different variations to try and extract the value but with no success:

NWF$('.nf-repeater-row:last .ItemType').val();
NWF$('.nf-repeater-row:last').val('.ItemType');
NWF$('.nf-repeater-row:last .ItemType').find('option').val();

etc...

Translate

Forum|alt.badge.img+7
  • 211 replies
  • January 8, 2019

I was also using Chrome console to test, and it worked for me. I would suggest playing around with it a little to see what is being returned. For example, change 'myFields.length - 1' to a number. You could also simply type myFields.length to ensure it's being populated. Test those and see what you get.

Translate

Forum|alt.badge.img+5
  • Author
  • 27 replies
  • January 8, 2019

Are you using a choice control or a lookup control for the drop down?

Translate

Forum|alt.badge.img+5
  • Author
  • 27 replies
  • January 8, 2019

I'll have a play around as you said. If I type myFields.length is does return the correct number of rows, so I can see what you're doing. I'll let you know if this leads me to the solution

Translate

Forum|alt.badge.img+7
  • 211 replies
  • Answer
  • January 8, 2019

My apologies. I used a Text field. I didn't realize you were using a Lookup field.


Try this code instead:

var myFields = NWF$('.myField option:selected');
var lastText = myFields[myFields.length - 1].text;
Translate

Forum|alt.badge.img+5
  • Author
  • 27 replies
  • January 9, 2019

It worked. Just had to change the value to -2.

var lastField = NWF$('.ItemType option:selected');
var lastText = lastField[lastField.length - 2].text;‍‍‍‍‍‍‍

Thank you so much.

Translate

  • 1 reply
  • September 23, 2019

Please i have repeating section and i want to get field value from last row only , below my code ... could help please

 

NWF$(".repeatedSection .nf-repeater-row:not('.nf-repeater-row-hidden')").each(function ()

  {

     var row = NWF$(this);

      var YearVal = row.find(".Year option:selected");

      var ActualVal = row.find(".Actual input");

      var TargetVal = row.find(".Target input");

 

     var actual2324 = ActualValue[ActualValue.length - 1];
     var target2324 = TargetlValue[TargetlValue.length - 1];

 

Translate

Forum|alt.badge.img+2
  • 8 replies
  • September 30, 2021

value is undefined, Test it before you post please

Translate

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie Settings