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

Re: Set default value to lookup field stopped working after Nintex Forms 2013 latest update

Jump to solution

Hey Patrick,

Were you able to modify the Lookup control's value via jQuery after the form was loaded?

I tried setting both the value and the initialValue of ko.dataFor(NWF$("#" + ctrlID_ApplicationID)[0]) from within an ajax success() method but neither worked, i even tried calling NWF.FormFiller.Functions.ProcessOnChange on the control but still nothing...

Reply
Not applicable

Re: Set default value to lookup field stopped working after Nintex Forms 2013 latest update

Jump to solution

Is the provided solution still working with version 2.9.2.10?

ko.dataFor(NWF$("#" + varStockLookup)[0]) is always undefined (Even if im trying to execute this code in the IE JavaScript Console after the popup form was loaded).

NWF$("#" + varStockLookup)[0] is providing the Input Element:

<input name="ctl00$ctl28$g_cf449c3f_dcde_42b4_8c46_68e71351d824$ctl00$ListForm2$formFiller$FormView$ctl18$94117087_6f85_4998_99ae_ac0d97337d90_hid" class="nf-ignore-getvalue " id="ctl00_ctl28_g_cf449c3f_dcde_42b4_8c46_68e71351d824_ctl00_ListForm2_formFiller_FormView_ctl18_94117087_6f85_4998_99ae_ac0d97337d90_hid" style="display: none;" type="text" formcontrolid="9afd0e97-d29c-4657-a09e-68285daee477"></input>

0 Kudos
Reply
rhia
Nintex Newbie

Re: Set default value to lookup field stopped working after Nintex Forms 2013 latest update

Jump to solution

Thank you for this - this worked beautifully for me.

0 Kudos
Reply
sdspecy
Nintex Newbie

Re: Set default value to lookup field stopped working after Nintex Forms 2013 latest update

Jump to solution

Dear Steven,

Would you mind explaining steps 2 and especially 4 a bit deeper? I'm quite a newbie at javascript
I can't seems to get it to work... all I get is "Loading..." text hanging beneath/over Lookup field's default "Please select a value..."
Lookup field w "Loading..." & "Please select a value..." one over another

I am passing an URL value to a Textbox field, which I'm using as a variable in the script (instead "option" parameter).
Don't know where I'm missing the point...
My code:
NWF$(document).on('change', '#' + userID, function () {
  var userIDLen = NWF$("#" + userID).find(ID-osebna_stevilka).length;
  if (userIDLen === 2) {
   NWF$("#" + userID).val(NWF$("#" + userID).find(ID-osebna_stevilka)[1].value);
  NWF$("input#" + userID).val(NWF$("#" + userID).find(ID-osebna_stevilka)[1].value);
  }
});

Thanks in advance!

0 Kudos
Reply
wayne_shen
Nintex Newbie

Re: Set default value to lookup field stopped working after Nintex Forms 2013 latest update

Jump to solution

Hello ,

Instead of using "ID-osebna_stevilka",  you need to use "option".

Lookup filed markup is look like,

<select>

<option></option>

<option></option>

<option></option>

...

</select>

I modified your code as following:

NWF$(document).on('change', '#' + userID, function () {
  var userIDLen = NWF$("#" + userID).find('option').length;
  if (userIDLen === 2) {
   NWF$("#" + userID).val(NWF$("#" + userID).find('option')[1].value);
  NWF$("input#" + userID).val(NWF$("#" + userID).find('option')[1].value);
  }
});

This code will set the default value only if this lookup only have one value.

In your case it will not work, since you have lots of choices.

For any questions, you can directly contact me via Skype (we are in the same company).

Best Regards,

Shen, Wei

Reply
jpmhuls
Nintex Newbie

Re: Set default value to lookup field stopped working after Nintex Forms 2013 latest update

Jump to solution

Today I figured out a way to set a lookup dropdown list using JavaScript with only a few lines of code and working in NF 2013 2.10.0. As a base for the code below I created a form with 2 lookups to a Currency list. Goal is to set the selected dropdown value of the 2nd one with the selected value of the 1st:

// First Dropdown - has JavaScript Client ID jsCurrency

var currencyCtrl = NWF$("#" + jsCurrency);

var currencySelection = currencyCtrl.val();                                                                          // Result as lookup string, e.g.  : 1;#EUR

var selectedCurrency = NWF.RuntimeFunctions.parseLookup(currencySelection,true);    // Lookup value itself                : EUR

// Second dropdown - has JavaScript Client ID jsSecondCurrency

var secondCurrencyCtrl = NWF$("#" + jsSecondCurrency);                                                        // this returns the input element

var selectCtrl2Id = jsSecondCurrency.replace('_hid','');                                                               // determine id of select element

var selectElement = NWF$("#" + selectCtrl2Id); ;                                                                        // this returns the select element

NWF$("#" + selectCtrl2Id + " option:contains(" + selectedCurrency +")").attr("selected", true);  // set select to specific lookup value

secondCurrencyCtrl.val(currencySelection);                                                                                // also store lookup string in input element

As mentioned this works now in two different libraries.

Reply
sjnbham
Nintex Newbie

Re: Set default value to lookup field stopped working after Nintex Forms 2013 latest update

Jump to solution

We had a workaround in production until we recently updated to 2.10.1.0. The list lookup control started showing Loading again and you couldn't select a value. Our previous workaround involved adding a text box that held the value used to filter the lookup control. So two things appear to have been affected:

1) Whereas we could set those text boxes' appearance to be hidden in the past, we can no longer do that and have the lookup list controls filter correctly. If we toggle the text boxes to visible, the lookups start filtering correctly. 

2) Even when the list lookup controls are filtered correctly, our previous JavaScript to select the value after filter wasn't working. So the user still had to manually select the single, filtered option from the list lookup.

With the help of an office mate who dug into the Nintex documentation a bit, we found a solution that works with Nintex Forms 2.10.1.0.

Enable the legacy list lookup control:


1. On the Central Administration home page, click Nintex Forms Management.
2. On the Nintex Forms Management page, click Manage Form Controls.
3. Under the Form Control Types table, in the Import text box, enter the following text:
Nintex.Forms.SharePoint.FormControls.SharePointLookupFormControlV1, Nintex.Forms.SharePoint, Version=1.0.0.0, Culture=neutral, PublicKeyToken=c52d764dcf7ec883
4. Click Import.

Configure the list lookup control:

1. Filtering

      Filter available selections: By a specified value

      Where filed: ID

      Filtered by value: fn-GetQueryString(customID)

      Action when no filter applied: Show all values

2. Advanced

      Client ID JavaScript variable name: UniqueVariableName

Add custom JavaScript to form so filtered value is selected and saved:

1. Settings > Custom JavaScript

2. Customize the following JavaScript for your form

/* Sets value for list lookup*/
NWF.FormFiller.Events.RegisterAfterReady(
   function updateList() {
      /*use client ID JavaScript variable name specified in the
      list lookup control in place of UniqueVariableName below*/
      var myVariable = NWF$("#" + UniqueVariableName).closest("div").find("select.nf-client-control");
      if (myVariable) {
         if (myVariable.length > 0) {
            myVariable = myVariable[0];
         }
         var myVariable2 = NWF$(myVariable).find("option")[1].value;
         NWF$(myVariable).val(myVariable2);
         /*this ensures the hidden field associated with the list lookup is populated before save*/
         NWF$(myVariable).trigger("change");
         }
      }
);
Reply
Highlighted
jpmhuls
Nintex Newbie

Re: Set default value to lookup field stopped working after Nintex Forms 2013 latest update

Jump to solution

In stead of looking for the <select> using its (calculated) ID (with _hid) a better alternative would be to use a more generic snippet:

var selectElement = NWF$("#" + jsSecondCurrency).parent().find('select');

0 Kudos
Reply
jagadishnpy
Nintex Newbie

Re: Set default value to lookup field stopped working after Nintex Forms 2013 latest update

Jump to solution

Hi 

Wayne's script worked for me .Is there anyway I can remove the 'Please select ' altogether from the dropdown .I want only one value in the dropdown and not even a space (for please select)in the dropdown.

Appreciate any help here

Thanks

0 Kudos
Reply
walter9000
Nintex Newbie

Re: Set default value to lookup field stopped working after Nintex Forms 2013 latest update

Jump to solution

Hello Ta all,

Great topic... I have been looking for something like this, I have used the code to set a default value to my lookup field, this last coding works for my solution, however the behavior is weird. sometimes set the value automatically, sometimes the value is not set up, this is weird I dont know if this is sounds familiar to you ? Mi Nintex version is  2.10.0.0

Thanks in advance

Walfred

0 Kudos
Reply