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

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

Jump to solution

I have set lookup default field value(from query string parameter) in my nintex forms as below and it was working fine.

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

    // here I was setting value "1" which is comes from query string

    // It was working fine before update

    NWF$("#" + ctrlID_ParentRequestDDL).val("1");

});

Now In my SP server I have installed latest Nintex Forms 2013 update i.e. 2.8.1.0, suddenly it's stopped working.

I have tried to find reason and I found that now in latest update, Nintex Forms uses Knockout JS to bind lookup field dropdown values e.g.,

<select title="" class="nf-lookup nf-ignore-getvalue nf-associated-control" id="ctl00_ctl39_g_c7140103_9f24_45a2_bf80_27a46acbea34_ctl00_ListForm2_formFiller_FormView_ctl118_lookupfa176a38_9bc4_4605_a0bc_2b9f7308ff55_Lookup" style="width: 100%;" formcontrolid="366ae762-ebb7-4480-baba-de982e7e361f" data-use-attribute-as-value="data-nfChoiceValue" data-bind="css: cssClass, options: lookupItems, optionsValue: 'id', optionsText: 'title', attr:{ title: helpText, id: id, disabled: !enabled(), formcontrolid: formcontrolid }, optionsAfterRender: setOptionTitle, value: selectedItem, event: { change: dropdownlistChanged }"><option title="Please select a value..." value="" data-nfChoiceValue="">Please select a value...</option><option title="1 - 1" value="1" data-nfChoiceValue="1;#1 - 1">1 - 1</option></select>

After update, it is loading dropdown value(by querying into lookup list) after document.ready function and till that time It is adding only one option into drop down i.e. "Loading..."

Currently in document ready function, I am only getting only one option that is "Loading...". and I have tried "NWF.FormFiller.Events.RegisterAfterReady" event but in that event also I am getting only one option i.e. "Loading".

So Now How can I achieve this functionality?

Any help is really appreciated.

Reply
20 Replies
kalpesh_vaghela
Nintex Newbie

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

Jump to solution

I found solution for it. Using following way you can set default value in lookup field dropdown in page load:

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

setLookupFields();

});

function setLookupFields() {

         // Getting view model of my lookup field dropdown control

   vmForApplication = ko.dataFor(NWF$("#" + ctrlID_ApplicationID)[0]);

   // Setting value to drop down

      vmForApplication.initialValue  = "some value";

}

Hope it will help someone.

Reply
amkarthi
Nintex Newbie

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

Jump to solution

Hi Kapesh vaghela,

The above drop down default value loading is working for me. Thanks for that post and help.

Reply
patrickabel
Nintex Newbie

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

Jump to solution

Kalpesh Vaghela​ I'm seeing the same issue, but in my case I'm needing to update the default value for a number of lookup fields and was hoping to do so via a class instead of an ID.

Any idea why your previous logic is no longer working? I was hoping to find the logic to "wait until all form controls have loaded" but am not seeing a means of doing that currently.

0 Kudos
Reply
kalpesh_vaghela
Nintex Newbie

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

Jump to solution

Patrick Abel That means you will give different class to each lookup fields instead of control ID and you want to find lookup field control using class instead of  control id? if Yes then is there any specific need of it as you can also get control ID in javascript variable instead of class?

0 Kudos
Reply
mgreene
Nintex Newbie

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

Jump to solution

I can get the same ko.dataFor object returned on a Lookup Control when I use a class by doing the following;

vmForCity = ko.dataFor(NWF$('.city select')[0]);

Issue for me is, the code provided doesn't seem to actually set the value for the field or make it appear to be selected either. When I save the form and reload it, it is still not set.

0 Kudos
Reply
Highlighted
wayne_shen
Nintex Newbie

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

Jump to solution

I use below JS to set the select default option and the value can be saved succesfully.

NWF$(document).on('change', '#' + yourcontrolid, function () {

  var yourcontrolidLen = NWF$("#" + yourcontrolid).find("option").length;

  if (yourcontrolidLen === 2) {

   NWF$("#" + yourcontrolid).val(NWF$("#" + yourcontrolid).find("option")[1].value);

  NWF$("input#" + yourcontrolid).val(NWF$("#" + yourcontrolid).find("option")[1].value);

  }

});

Reply
sjnbham
Nintex Newbie

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

Jump to solution

Thanks Wayne!

Your code snippet worked for me. The one marked as answered didn't. I'm using Nintex Forms 2013 2.9.0.0. Nintex Support says the lookup control changed with 2.5.0.0 and up.

0 Kudos
Reply
patrickabel
Nintex Newbie

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

Jump to solution

Steven/Wayne,

I've had success as well setting the default value of a lookup field on a "change" event but where I have struggled is setting that default on initial load of the form. You'll notice that when the form-filler, scripts, and DOM have all loaded, these lookup controls are still "loading..."

I was looking for what Nintex event I could wait for in order to set the default value once the controls have loaded on the page without having to use a timer or a button to trigger the event.

Reply
sjnbham
Nintex Newbie

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

Jump to solution

Wayne's code works for me in the following use case:

1) Add the code to the Form Settings > Custom JavaScript field

2) Customize the code to reference the Client ID JavaScript variable name of my control

3) Create a Single Line text box and set the default value to a query string parameter I'm passing in the URL

4) Filter the lookup list control using the value of the single text box (this allows for blank URL parameters if users go directly to the new form instead of using a custom link with parameters from another form).

5) Save the Nintex form.

6) When a new list item form is opened, the control filters down to the single option I've passed in the URL parameter and then the JavaScript selects that single option as the default instead of just showing "Please select a value...".

In all of our testing, the lookup list loads and populates with the single option as default. But make sure you're using Forms 2.5.0.0 or higher or the code may not work.

Reply