Nintex Form Repeated control contains choice field (Dropdown)values dynamically removed

  • 28 April 2016
  • 5 replies
  • 4 views

Badge +3

Hi,

Initially in the form I have choice field(Radio buttons values: TEST1, TEST2, TEST3, TEST4). I have repeating section that contains choice control (dropdown values : Form1,Form2,Form3,Form4). My question is if I select Test1 radio button, I need to control choice values using javascript i.e I need to show only Form 1 in dropdown. If I select Test2 in radio button selection I need to show Form1 and Form 2 in drop down list. If I select Test 3 I need to show all values in dropdown.

Thanks,

Raman.


5 replies

Userlevel 5
Badge +9

Hi Ramana,

You can add a css class to the choice field displayed as radio buttons (in the control settings, Formatting section, Control CSS class field - for example: my-radio-buttons) and another css class to the choice field displayed as a dropdown list (in the control settings, Formatting section, Control CSS class field - for example: my-dropdown-list).

Use the following javascript to execute a script each time the value of the radio buttons changes:

     NWF$(".my-radio-buttons input[type=radio]").change(function() {

               if (this.value == "Test1") {

                    // Show only Form1 in dropdown

               } else if (this.value == "Test2") {

                    // Show only Form1 and Form2 in dropdown

               }

     });

Then, to only show and hide a value in a dropdown, you first need to remove all the options, then add the options that you'd like to be displayed. To do that, when the form loads, save all the options in a variable using the following script:

     var dropdownListOptions;

     NWF$(document).ready(function(){

          dropdownListOptions = NWF$("select.my-dropdown-list").first().children();

     });

To remove all the options except the first one (which is "Select a value"), use the following script:

     NWF$("select.my-dropdown-list").children("option:not(:first)").remove();

To add the option which value is "Form1", use the following script:

     NWF$("select.my-dropdown-list").append(dropdownListOptions.filter("[value='Form1']")[0].outerHTML);

The whole script should look like this:

var dropdownListOptions;

NWF$(document).ready(function(){

     dropdownListOptions = NWF$("select.my-dropdown-list").first().children();

     NWF$(".my-choice-control input[type=radio]").change(function() {

          if (this.value == "TEST1") {

               NWF$(this).parents(".nf-repeater-row").find("select.my-dropdown-list").children("option:not(:first)").remove();

               NWF$(this).parents(".nf-repeater-row").find("select.my-dropdown-list").append(dropdownListOptions.filter("[value='Form1']")[0].outerHTML);

          } else if (this.value == "TEST2") {

               NWF$(this).parents(".nf-repeater-row").find("select.my-dropdown-list").children("option:not(:first)").remove();

               NWF$(this).parents(".nf-repeater-row").find("select.my-dropdown-list").append(dropdownListOptions.filter("[value='Form1']")[0].outerHTML);

               NWF$(this).parents(".nf-repeater-row").find("select.my-dropdown-list").append(dropdownListOptions.filter("[value='Form2']")[0].outerHTML);

          }

     });

});

Hope this helps

Badge +3

Thank you for posting solution. I have one question initially as form loads I am hiding repeating section until user selects any of choice from drop down, for that I apply rule: IsNullOrEmpty(Radio button choice). If I selects test3 directly , some controls inside repeating control not shown.

Userlevel 5
Badge +9

in the solution that I posted I assumed that both dropdown list and radio buttons where in the repeating section. Is that your case?

Badge +3

Yes. I have 2 repeating sections, the solution u posted is my first repeating section. In other repeating section:

I have Form Fields Look like this..

For Example purpose

happy.pngEngineer

happy.pngConstructor

happy.pngMaintenance

happy.pngIT

They are choice values (Type Radio Buttons) Name Request

184030_pastedImage_0.png

I have Repeating Section contains choice (dropdown) and people picker

184031_pastedImage_1.png

The values in choice are A, B, C, D

If i selects Engineer from Request Radio button (value Engineer) one row appear, If I selects Request Radio button (value Maintenance) 3 rows appear. everything working fine, but after the page loads if i selects Maintenance from radio button

184034_pastedImage_2.png

The alignment is goes away, If i selects any other value (not Maintenance) then it is working fine. And one more thing after the page loads if i selects Engineer first and change option value to Maintenance then it is working.

184035_pastedImage_3.png

Userlevel 5
Badge +9

Can you list all the formatting rules that you've created regarding this repeating section and to which control(s) you've applied them?

Reply