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".
Solved! Go 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.
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:
And I've used different variations to try and extract the value but with no success:
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.
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
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;
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.
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];