cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
ms
Nintex Newbie

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

Jump to solution

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".

Labels: (1)
0 Kudos
Reply
7 Replies
chaddavis
Nintex Newbie

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

Jump to solution

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. 

0 Kudos
Reply
ms
Nintex Newbie

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

Jump to solution

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...

0 Kudos
Reply
chaddavis
Nintex Newbie

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

Jump to solution

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.

0 Kudos
Reply
ms
Nintex Newbie

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

Jump to solution

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

0 Kudos
Reply
ms
Nintex Newbie

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

Jump to solution

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

0 Kudos
Reply
chaddavis
Nintex Newbie

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

Jump to solution

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;
Reply
ms
Nintex Newbie

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

Jump to solution

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.

0 Kudos
Reply