Repeating section drop down list options

  • 23 September 2015
  • 29 replies
  • 19 views

Badge +3

Hi all,

I have a drop down list in a repeating section, where the option values are populated dynamically using JavaScript below.

NWF$("#" + accounts).append(options);

where accounts is the drop down list name and options are values that is populated as choices.

This works fine and the drop down list in the repeating section gets populated.

However, when I add a new row in the repeating section, drop down list in the new row does not have these choices.

Is there a way I can maintain the choices throughout the entire repeating section?

If not, how can I access the new row to populate the same choices?

thanks.


29 replies

Userlevel 5
Badge +9

Take a look at this article :

JavaScript events in Nintex Forms

You can execute your method that adds options in the NWF.FormFiller.Events.RegisterRepeaterRowAdded function.

Hope this helps

Userlevel 5
Badge +9

Also as it is a repeating section, you should add css class to your dropdown list control instead of using the ID of the control. You can execute the following to add options to this control each time a row is added :

NWF$(".css-class-of-your-repeating-section .nf-repeater-row:last .css-class-of-your-dropdown-list select").append(options);

As the ID is unique, it will only be available for the control in the first row. If you add a css class in the settings of the control, this class will be added on the control in each row.

Hope this helps

Badge +3

That worked! you are great! thanks a lot. I would never have guessed that command.

Userlevel 5
Badge +9

Cool, I'm glad that it helped you !

Badge +3

Hi Caroline, I have another question on the repeating section, I tried accessing the selected value of drop down list on the last row using below line but does not seem to work. Do I need to add anything else?  Also, is there a way I can loop through each repeating section rows using javascript? thanks again.

NWF$(".css-class-of-your-repeating-section .nf-repeater-row:last .css-class-of-your-dropdown-list select").val();

Userlevel 5
Badge +9

To access the selected option in the dropdown list on the last row, you can use the following :

NWF$(".css-class-of-your-repeating-section .nf-repeater-row:last .css-class-of-your-dropdown-list select option:selected");

To loop through each row, you can use the following :

NWF$(".css-class-of-your-repeating-section .nf-repeater-row:not(.nf-repeater-row-hidden)").each(function() {

     // Add your code here

     NWF$(this).find(".css-class-of-your-dropdown-list select option:selected");

});

Hope this helps

Badge +3

That worked well, thanks.

Badge +3

Hi Caroline,

The form is working well but when I submit the form, there are problems with dynamically populated repeating section data using JavaScript.

1. When I assign a value to a email column in repeating section using JavaScript like NWF$(".euclass .nf-repeater-row:last .email").val("test"); it works well. However, when I save the form and view the saved XML, email node is empty. If I change the value of this email column before submitting form, then the value comes up in the saved XML.

2. Assigning new options/choice to a drop down list in repeating section works well using the JavaScript, however, then I try to submit the form, SharePoint gives error. I suspect that is because the options/choices dynamically assigned on the form are not in the original options/choices when the drop down list was created. For example, a drop down list column was created with choices "a", "b" and "c". Nintex form assigns new value "d" using NWF$(".css-class-of-your-repeating-section .nf-repeater-row:last .css-class-of-your-dropdown-list select").append("<option value="d">d</option>);   then it throws an error.

Would you have any suggestions on these issues? thanks again.

Sam

Userlevel 5
Badge +9

For your first question, you can try to add the following :

NWF$(".euclass .nf-repeater-row:last .email").val("test");

NWF$(".euclass .nf-repeater-row:last .email").focus();

NWF$(".euclass .nf-repeater-row:last .email").blur();

but I'm not sure if it will work.

For your second question, you cannot add custom drop down options but what you can do is having all the drop down options and in javascript, removing the options that you don't want to be displayed.

For example, your drop down list column was created with options "a", "b", "c" and "d" and then in javascript, you can remove options "a" and "b".

Hope this helps

Badge +3

Thanks for the reply. I tried focus() and blur() but unfortunately, it did not populate the new value in the saved repeating section XML.

It seems if there is already a value saved in a repeating section and I want to over-write that value via JavaScript NWF$(".euclass .nf-repeater-row:last .email").val("test"), it will show the new value "test" on the form but it will not save it when the form is submitted. I ended up saving the XML to another text value and accessing it from there.

Userlevel 5
Badge +9

What type of control is the one with the "email" css class ?

Badge +3

It is a single line text field, thanks.

Userlevel 5
Badge +9

Is the field enabled ?

Badge +3

No, it is not enabled as we don't want users to modify the populated value from the JavaScript call. I will try enabling it and check if it saves the changes, thanks. If this works, is there another way to disable field edit?

Userlevel 5
Badge +9

The fields which are disabled are not taken into account if they are edited.

What you can do is to add another field enabled that you can hide with a formatting rule (the condition would be only : true) and change both fields with javascript. When form loads, you can change the value of the disabled field with the value of the enabled but hidden field.

Hope this helps

Badge +3

Thanks for the reply, enabling field worked well and now I can save the changes on form submit. I created a hidden field as a workaround as well.

Userlevel 5
Badge +9

You're welcome ! It's great that you could find a solution to your problem

Userlevel 5
Badge +9

Yes, it is possible.

You will have to add an event listener on all your controls to execute a custom JS function when the change event fires.

In this custom function, you have access to the control that has been modified. As the current control is Inside a row, you can get the row by using the parent() function which returns the parent balise of the current one (I know it's not the better way to do that because you call the parent() function several times and it depends on the type of control but it's the only one I found...).

Here's an example :

NWF.FormFiller.Events.RegisterAfterReady(function(){

NWF$("input.css-class-of-a-textbox-in-a-repeating-section").change(my_custom_function);

});

function my_custom_function() {

var currentRepeatingSectionRow = NWF$(this).parent().parent().parent().parent().parent();

var currentTextBoxValue = NWF$(this).val();

// Change the value of a dropdown list in the same row

currentRepeatingSectionRow.find('.css-class-of-dropdown-list).val(currentTextBoxValue);

}

Hope this helps

Userlevel 5
Badge +9

You can add a css class to the dropdown control by populating the "Control CSS class" field in the settings of the control and then execute the following script in your custom function :

$row.find("select.dropdown-css-class").append("<option value=1>gone</option>");

Userlevel 5
Badge +9

the semicolon is missing after the append function

Userlevel 5
Badge +9

Is there a JavaScript error ?

Have you added the cssman css class in the "CSS class" or "Control CSS class" field in the settings of the dropdown ?

Userlevel 5
Badge +9

The "Control CSS class" is OK.

Do you have a javascript error (you can check using the debugger of your browser - F12 for IE and Chrome) ?

Can you try by replacing this line :

var options = "<option value=101>gone</option>";

with this line :

var options = "<option value='101'>gone</option>";

Userlevel 5
Badge +9

you're welcome wink.png

can you check with the debugger if the css class "cssman" is correctly added to the "select" balise corresponding to the dropdown in the repeating section ?

Is this dropdown a choice control or a list lookup control ?

Userlevel 5
Badge +9

With which css do you get the value of your dropdown list ?

Userlevel 5
Badge +9

Sorry, I wanted to write : With which javascript ?

Reply