cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to set the default value of a single line textbox to a calculation to lookup()

I have list lookup and a single line text box in a repeating section and I would like the lookup selection to populate the textbox default value based on the lookup value. And the user should have the ability to update the textbox value (hence this cannot be a calculated value)

Labels: (1)
Tags (1)
0 Kudos
Reply
3 Replies
Not applicable

Re: How to set the default value of a single line textbox to a calculation to lookup()

Here is how I got around this.  First step was to make the text box and a calculated field in the repeating section.  I then set the CSS class of txtControl for the text box and rsLineItems for the repeating section.

 

On the calculated field, I first set it to a lookup based on the dropdown to make sure the correct data was being returned.  I then wrapped that lookup in a javascript call by making the following the formula of the calculated column:

 

setControl(currentRowNumber(), lookup("List Title", "ID", DropDownVal, "Return Row"));

 

The currentRowNumber() function is the key there.  It returns the row of the repeating section that the field is on, which is what allows us to find the correct instance of the textbox to alter.

 

Finally, I added the following JS function as Custom JavaScript on the form:

 

function setControl(rowNum, value){

     repeatingSection = NWF$('.rsLineItems');

     if (value != ""){

         //This line filters any HTML placed by Nintex.  Leave out if using a numerical column return

         var regex = /( |<([^>]+)>)/ig, result = value.replace(regex, "");

         //This grabs EVERY textbox with the CSS class of txtControl

         var Textboxes = NWF$(repeatingSection ).find('.txtControl');

         //And this loops through those textboxes until the index matches the passed row number

         NWF$.each(Textboxes, function (index) {

                if (index == rowNum){

                     NWF$(this).val(result);

                }

         });

     }

}

 

You could easily set this up to handle multiple controls by also passing the class name to the function and multiple repeating sections by also passing the RS class.  Since the javascript is part of the calculation, it's called every time the field recalculates.

 

The final step is just to add a little custom CSS to the page to attach "display: none;" on your calculated fields so your users aren't treated to a "#Value!" on the page under your textboxes.

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: How to set the default value of a single line textbox to a calculation to lookup()

Thank you for this. It was really helpful.

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: How to set the default value of a single line textbox to a calculation to lookup()

Just wanted to pass on this in case any other newbies like me and need something similar. 

The above (  NWF$(this).val(result);  ) works great if I was importing just text from another list.

Recently I needed to import a list column with html stuff like bold and bullets.

This works for that: 

NWF$(this).html(result).find('.nf-repeater-deleterow-image').css("visibility", "hidden");

Use a label with the CSS set to "txtControl"

Repeating section CSS set to "rsLineItems"

Especially useful when you have 40 plus different sets of text. 

Auto-size works great. Spacing is good.

Next thing to do if needed and I am sure it will be is ensure the ordering matches up with current results. For now the users can only add and edit. No deleting or reordering with out permission.

Thanks again @Jai the info.

0 Kudos
Accept as Solution Reply