Skip to main content
Nintex Community Menu Bar

Auto populate value in drop-down menu

  • Aug 16, 2017 1:42 PM UTC
  • 16 replies
  • 97 views
  • Translate All

Forum|alt.badge.img+7

Hi

I want to auto-select field values based on values elsewhere in the form.

============================

Example:

Drop-down menu A: Creature

Choices: Man, Dog, Spider

Drop-down menu B: Species

Choices: Human, Canine, Arachnid

When a user selects Man in menu A,  menu B auto-populates as Human. 

When a user selects Dog in menu A,  menu B auto-populates as Canine. 

When a user selects Spider in menu A,  menu B auto-populates as Arachnid. 

=============================

These menu choices are not based on lookups of other lists. Using lookup lists is not practical for us. We need our forms in one list without the requirement of maintaining supporting lists.

I understand that InfoPath allows this functionality quite easily, but can't seem to find something similar in Nintex Forms.

I don't mind using JavaScript, just not sure if this can be done without in the latest version or how I would go about doing it. 

Appreciate any help that can be offered.

Platform: Nintex Forms 2013 2.10.1.0

Environment SharePoint 2013 Enterprise

16 replies

Forum|alt.badge.img+13

Do these two threads give you a good starting point?

How to set default value some option in drop down list look up using JQuery or Javascript 

 

Translate

Forum|alt.badge.img+14
  • Scholar
  • Aug 17, 2017 10:36 PM UTC

here is very similar case -  

Translate

Forum|alt.badge.img+7
  • Author
  • Aug 18, 2017 10:11 AM UTC

Thanks for the links but they don't really answer my question. I don't want to auto populate fields when the form is opened. I want to create a link between values in two drop-down menus. Selecting one value in menu A changes the value in menu B, dynamically, while the form is open.

Translate

Forum|alt.badge.img+13

Hi Harry,

Marian's link goes specifically into how to modify the value of one field with the event being the change of another. The two links I provided give more details on how to set a dropdown field using Javascript. You can use both of these to create the solution you're looking for. 

You can also check out this resource: How to Create Cascading Choice Controls – Nintex Forms  from

Translate

Forum|alt.badge.img+14
  • Scholar
  • Aug 22, 2017 10:29 PM UTC

here is the script which (re)sets value of dropdown control (choice) based on value of other dropdown control (choice as well).

second control follows each change of the first one. if first control is set to a value out of defined list, second control is cleared.

jsDDA_Creature and jsDDB_Species are javascript variables configured for respective controls.

the script should be placed into form settings >> Custom JavaSript

NWF.FormFiller.Events.RegisterAfterReady(function () {  
    NWF$('#'+jsDDA_Creature).change(function(evt){
        switch(evt.target.value){
            case 'Man' :
                NWF$('#'+jsDDB_Species).val('Human');
                break;
            case 'Dog':
                NWF$('#'+jsDDB_Species).val('Canine');
                break;
            case 'Spider':
                NWF$('#'+jsDDB_Species).val('Arachnid');
                break;
            default:
                //no creature
                NWF$('#'+jsDDB_Species).val('');
                break;
         }
    })
})
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

choice‌ dropdown‌ choice dropdown dropdown choice set dropdown value by other dropdown set choice value by other choice ‌ populate dropdown populate choice

Translate

Forum|alt.badge.img+7
  • Author
  • Aug 23, 2017 7:55 AM UTC

Thank you very much for your effort Marian but I can't get that to work. The values are not changing.

I put the script in the form settings custom Javascript section and gave the drop-down menus variable names in their respective settings (store client id in javascript variable). 

Am I missing something else?

Translate

Forum|alt.badge.img+14
  • Scholar
  • Aug 23, 2017 8:08 AM UTC

can you check developer console for any errors?

press F12 in browser, in window that opens switch to 'Console' tab, return to browser and run the form. watch dev console whether there are not any errors reported.

Translate

Forum|alt.badge.img+7
  • Author
  • Aug 23, 2017 8:12 AM UTC

I checked it yes and it said jsDDA_Creature is undefined.

I can't tell what's nintex wrap code and what's not.  Is the jsDDA and jsDDB some type of Nintex code or wrapper or just an example variable name that I can change?

Translate

Forum|alt.badge.img+7
  • Author
  • Aug 23, 2017 8:18 AM UTC

OK it's working after I added the jsDDA and jsDDB to the respective control names. 

Many thanks for your help on this. Apologies I 'm such an amateur at JS. Hopefully I can improve soon but getting to the level above may take some time happy.png

Translate

Forum|alt.badge.img+7
  • Author
  • Aug 23, 2017 8:19 AM UTC

Is there a reference guide for nintex JavaScript code requirements like wrapping code?

Translate

Forum|alt.badge.img+7
  • Author
  • Aug 23, 2017 9:53 AM UTC

If I want to repeat this for other controls on the form can I repeat the code beneath the existing one but change the variable names and names of the controls?

Translate

Forum|alt.badge.img+14
  • Scholar
  • Aug 23, 2017 12:10 PM UTC

In principle yes.

In fact it's enough if you 'repeat' just body of RegisterAfterReady function. But if you 'repeat' whole block nothing wrong happens. Note however, that different type of controls might need to be set  different ways

Translate

bamaeric
Nintex Partner
Forum|alt.badge.img+15
  • Nintex Partner
  • Aug 23, 2017 2:10 PM UTC

Handy solution.  I was having trouble getting this to work in Nintex Forms 2013 at first, but I finally figured it out.  I had to add a semicolon (;) at the end of the added code after the last }) in the Custom JavaScript.

Translate

Forum|alt.badge.img+14
  • Scholar
  • Aug 23, 2017 2:44 PM UTC

yeah, sometimes nintex loses line feeds at the end of custom code, especially if you copy & paste piece of code, and places follow up code right after the closing bracket. javascript engine has then problems to parse it. so one have to go to the custom code once again and append few of them.

Translate

Forum|alt.badge.img+9
  • Jan 3, 2018 11:39 PM UTC

Hi Marian

Will this work for list lookup dropdown lists, in a repeating section? I tried it and it didn't work.

Translate

Forum|alt.badge.img+14
  • Scholar
  • Jan 5, 2018 11:55 AM UTC

Hi ‌,

generally yes.

but this script needs to be tweaked to address control(s) in a proper repeater row(s).

Translate