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

Append value from (dropdown or calculated value or PoG field) to a text field

Jump to solution

Hello

 

I have a similar request as this post, where I have a repeated section with a dropbox to select from: Recipient or Somebody else. Along side it, there is a SingleField where I like to have copy the Name of the User (People or Group field) into that when [Recipient] is selected, otherwise if somebody else then the singleField is blank for the user to manually type the name in.

CollectedBy.jpg

 

PoG field:  [RecipientName]

DropBox: [CollectedBy] *this will hide when "Somebody else" is selected

SingleField: [CollectedByUser]

 

Cal.Value [PoGName] this is to show the Surname, Firstname as in a format.

userProfileLookup(RecipientName,"PreferredName")

What I like to achieve is that, whatever name is selected/typed in the PoG field, then it also replicate or copied over to the [CollectedByUser] within the repeated section, when [Recipient] is selected.

 

To test it, I have tried to use the following which works only on the 1st entry within the repeated section!

 

NWF$(document).ready(function(){  
 var setRecipient = NWF$("#" +varCollectedBy); 
setRecipient.change(function(){
  NWF$("#" + varCollectedByUser ).val('Test');
  });
 });

Wonder how to copy the text from a PoG field or calculated field into the [CollectedByUser] field within all wors of the repeated section?

Labels: (1)
Tags (1)
0 Kudos
Reply
9 Replies
emha
Nintex Newbie

Re: Append value from (dropdown or calculated value or PoG field) to a text field

Jump to solution

to address a control in all the rows in repeating section configure a CSS class for the control, and use class selector like

NWF$(".CollectedByUserClass").val('Test');
0 Kudos
Reply
bimi82
Nintex Newbie

Re: Append value from (dropdown or calculated value or PoG field) to a text field

Jump to solution

Hi EMHA

 

Strangely enough, your suggested formula only worked in a strict order!
By this I mean, if you add 5 items and changed the [ItemStatus] then it worked however ... if you added new rows in different order then it didn't work.

 

To overcome this problem, I then also added a Control Class for the dropdown option:

 

NWF$(document).ready(function(){  
 var setRecipient = NWF$(".CollectedByClass");  
 setRecipient.change(function(){ 
  NWF$(".CollectedByUserClass").val('Test'); 
  });
 });
 

The one-million question is though:
How would I populate the .val(.....) with the value which is already in a PoG field or calculated value?

 

I thought that maybe the value needs to be stored into a variable and then it be used in the .val() function, for example like this:

 

NWF$(document).ready(function(){ 
	var setRecipient = NWF$(".CollectedByClass"); 
	var PoGName = new NF.PeoplePickerApi('#' + varRecipientName);
	setRecipient.change(function(){ 
		NWF$(".CollectedByUserClass").val(PoGName); 
	}); 
}); 

However, the result in the text field shows [Object Object] instead of user's name.

0 Kudos
Reply
emha
Nintex Newbie

Re: Append value from (dropdown or calculated value or PoG field) to a text field

Jump to solution
By this I mean, if you add 5 items and changed the [ItemStatus] then it worked however ... if you added new rows in different order then it didn't work.

I'm not sure what you mean with this....

how do you add rows in one or the other/different order?

how does [ItemStatus] change affetcs this? it's nowwhere referenced in the script, as far as I can see...

can you explain, post some examples?

 

 

 

To overcome this problem, I then also added a Control Class for the dropdown option:

if you mean this line of code

var setRecipient = NWF$(".CollectedByClass");  

then the rest of the code is not valid anymore.

setRecipient is now collection of controls having '.CollectedByClass'. if you assigned the class to the editbox within repeating section you get collection of all the editboxes within repeating section (all the visible + one for editbox in hidden repeater row)

collection of controls connot fire a change event nor you can set a value of whole collection. you would need to iterate the collection with .each() function.

 

 

 

 

I thought that maybe the value needs to be stored into a variable and then it be used in the .val() function, for example like this:

that cannot help at all, since the whole script make no sense now.

 

 

 

However, the result in the text field shows [Object Object] instead of user's name.

that's correct, PoGName is an object, not a value of people control....

 

 

 

What I like to achieve is that, whatever name is selected/typed in the PoG field, then it also replicate or copied over to the [CollectedByUser] within the repeated section

if you want to follow a change on people or group form control (RecipientName), why have you written onchange handler for some other control - varCollectedBy/CollectedByClass?

 

 

 

 

please clarify all the doubts, resp. try to explain in more details what exactly you want to achieve.

 

 

 

 

0 Kudos
Reply
bimi82
Nintex Newbie

Re: Append value from (dropdown or calculated value or PoG field) to a text field

Jump to solution

@emha 

 

of course, nothing makes sense now because there are various things thrown out there.

So, to start from sratch let me explain Smiley Happy

 

Scope:

I have designed a form to book some items which stores some information such as,  Recipient's name , Amout of Items, The Item details, etc.

 

People of Group field [RecipientName] [.RecipientNameClass]

Calculated Value [showRecpientName] [.showRecpientNameClass]

userProfileLookup(RecipientName,"PreferredName")

 

The form also used the Repeated Section to store the Item Details, such as ItemDescp, Date, whether it is Booked or Collected and especially by whom it was collected.

 

- DropDown [CollectedBy] [.CollectedByClass]   (Please select, Recipient, Somebody else)

- Single Line TextBox [CollectedByUser] [.CollectedByUserClass]

 

The Purpose

I would like to make it more efficient so that, when the DropDown changes to "Recipient" then ideally should copy the value (the name) from the Recipient's Field which is a PoG field or if that is not possible then I also added a calculated value formula to display the user's full name from the PoG field.

 

The Code

Of course, I am not a coder/developer, so I basically copy & pasted and tried things around and the below code, with your help, at least works to a certain extend Smiley Happy

 

 NWF$(document).ready(function(){  
 var setRecipient = NWF$(".CollectedByClass");  
 setRecipient.change(function(){ 
  NWF$(".CollectedByUserClass").val('Test'); 
  });
 });

The above code, does update the Single Line Textbox with 'Test' whenever the DropDown is changed, whether is Recipient or Somebody else. It also works indipendalty per row, which does not interfier with each other e.g. it does not update any other rows when I change the dropdown in any rows. So, as a simple test, the above works fine ...

 

However... now the main points are missing:

 

1) Update the SingleLine Textbox only when DropDown changes to "Recipient" only and leave blank by default or when Somebody else is selected.

2) Update the SingleLine Textbox with the value from the Poeple or Group field or from the calculatedvalue (either way) when the DropDown is selected to "Recipient".

 

Overall, instead of the user having to type in that the recipient's name who collected it, why not have it somehow automated based on the selected value. Of course, if it's somebody else then you would expect that the person's name to be manually typed in Smiley Happy

 

Makes sense?

 

 

0 Kudos
Reply
emha
Nintex Newbie

Re: Append value from (dropdown or calculated value or PoG field) to a text field

Jump to solution

ok, now that makes more sense.

 

I think following code might suit you 

 

NWF.FormFiller.Events.RegisterAfterReady(function () {
    NWF$(".CollectedByClass").change(function(evt){
        var currRow = NWF$(evt.target).closest('.nf-repeater-row');
        var txtboxOnCurrRow = currRow.find(".CollectedByUserClass input.nf-associated-control");
        var PPFieldValue =  NWF$('#' + jsvarRecipientName).val();   // replace jsvarRecipientName (PoG control) with jsvarShowRecpientName if you want calc. val. control gets copied
        var currDDValue = evt.target.value;
        
        if (currDDValue == "Recepient" ){
            txtboxOnCurrRow.val(PPFieldValue); 
        } else if (currDDValue == "Somebody else" ){ 
            txtboxOnCurrRow.val('*change acc. needs*');
        } else{
            txtboxOnCurrRow.val('*empty value*'); 
        }
    });
});
Reply
bimi82
Nintex Newbie

Re: Append value from (dropdown or calculated value or PoG field) to a text field

Jump to solution
Hi @emha

Thanks for your solution Smiley Happy

I had to remove the input.nf-associated-control from the var txtboxOnCurrRow, as it would not work with it ... not sure why not and the currDDValue == "Recipient" was spelled "Recepient".

Hint: I had to use the varShowRecipientName from the calc.value instead because the domain\username was copied if the varRecipientName was used.

Works perfectly now ... amazing.
0 Kudos
Reply
emha
Nintex Newbie

Re: Append value from (dropdown or calculated value or PoG field) to a text field

Jump to solution

I'm glad it works Smiley Happy

 

 

 

 

I had to remove the input.nf-associated-control from the var txtboxOnCurrRow, as it would not work with it ... not sure why not

have you customized appearance or control mode for the control?

have you noticed and preserved a space between ".CollectedByUserClass" and  "input.nf-associated-control"? maybe if you just copy&pasted code from this page it get copied over as non-breakable space (  ) instead of regular space - try to retype the selector.

0 Kudos
Reply
bimi82
Nintex Newbie

Re: Append value from (dropdown or calculated value or PoG field) to a text field

Jump to solution
Hi,

yes the space was there and I even manually entered the "input.nf-associated-control" line but it works without this line otherwise it doesn't.
When I inspect the textbox field, there is nothing named after nf-associated-control

What is it used for anyway?
We use Nintex Form Version: 4.3.3.0


By the way, can I use the same script to clear .datepicker field when a dropdown [ItemStatus] changes to "Collected" ? Or is there a substanical change in the code?
0 Kudos
Reply
emha
Nintex Newbie

Re: Append value from (dropdown or calculated value or PoG field) to a text field

Jump to solution

ok, that likely changed on 2016, I've tested with 2013.

0 Kudos
Reply