Skip to main content
Nintex Community Menu Bar

How to set default for a lookup column using jquery in nintex

  • Mar 23, 2018 11:27 AM UTC
  • 13 replies
  • 115 views
  • Translate All

Forum|alt.badge.img+2

I was wondering anyone could shed some lights on this.

 

I want to set default to EN ENGLISH on my list lookup (Language) as below but its editable.

 

 

 

JQuery

NWF$(document).ready(function() {   
 
  //setLookupField(DetailLanguage, 'EN ENGLISH');
}); NWF.FormFiller.Events.RegisterAfterReady(function () {
 
 if (DetailLanguage == "Please select a value..."){
 
 setLookupField(DetailLanguage, 'EN ENGLISH');
    setTimeout(function(){ setLookupField(DetailLanguage, 'EN ENGLISH')},1000);
    setTimeout(function(){ setLookupField(DetailLanguage, 'EN ENGLISH')},2000);
 }else{
  setLookupField(DetailLanguage, 'EN ENGLISH');
    setTimeout(function(){ setLookupField(DetailLanguage, 'EN ENGLISH')},1000);
    setTimeout(function(){ setLookupField(DetailLanguage, 'EN ENGLISH')},2000);
  
 }});
function setLookupField(lookupField, lookupValue) {
 var lookupID = lookupField.substring(0, lookupField.length-4);
 var selectField = NWF$("#" + lookupID + " > option");
 
 for (var i = 0; i < selectField.length; i++){
  var option = selectField;
  if(option.text == lookupValue){
   NWF$("#" + lookupID).val(option.value);
   NWF$("#" + lookupField).val(option.getAttribute("data-nfchoicevalue"));
   NWF$("#" + lookupField).trigger("change");
   NWF$("#" + lookupField).trigger("blur");
   break;
  }
 }
}

13 replies

Forum|alt.badge.img+9
  • Nintex Partner
  • Mar 26, 2018 8:17 AM UTC

In O365, you can use this script to update a list lookup value:

var valueText = "EN ENGLISH";

var yourControl = NWF$("#"+yourControlId);

var value = yourControl.find("option[title='" + valueText + "']").attr("value");

yourControl.val(value);

yourControl.parent().find("input").val(valueText + "#--#" + value);

NWF$(NWF$(this).parent().find("input")[1]).val(value);

Hope this works

Translate

Forum|alt.badge.img+2
  • Author
  • Mar 28, 2018 3:41 AM UTC

May I know what is [1] referring to?

Translate

Forum|alt.badge.img+2
  • Author
  • Mar 28, 2018 3:51 AM UTC

where do i put this?

Translate

Forum|alt.badge.img+2
  • Author
  • Mar 28, 2018 7:11 AM UTC

Hi Caroline Jung

it's working do you mind explaining these lines?

var valueText = "EN ENGLISH"; // default value which i needed

var yourControl = NWF$("#"+yourControlId); // jquery name of the above item

var value = yourControl.find("option[title='" + valueText + "']").attr("value"); // set var value to en english in option list lookup

yourControl.val(value); //set en english to yourControl

yourControl.parent().find("input").val(valueText + "#--#" + value);  //?

NWF$(NWF$(this).parent().find("input")[1]).val(value);  //? why the [1] ? is it the list item id of the particular item ?

Translate

Forum|alt.badge.img+2
  • Author
  • Mar 29, 2018 11:32 AM UTC

Caroline Jung‌

Hi,

I dont know why suddenly the default to en english isnt working

its triggering from this line

yourControl.parent().find("input").val(valueText + "#--#" + value);  

Translate

Forum|alt.badge.img+4

If you know the ID of your element, you can do this :

var control = ko.dataFor(NWF$("#" + varMyControlID)[0]);
control.initialValue  = "X";

where X is the ID of your element in the list

Translate

Forum|alt.badge.img+9
  • Nintex Partner
  • Apr 5, 2018 5:48 PM UTC

Hi, 

Sorry for the delay, here are explainations:

var valueText = "EN ENGLISH"; // Setting the title of the option to select in the list lookup field

var yourControl = NWF$("#"+yourControlId); // Getting the list lookup control on the form

var value = yourControl.find("option[title='" + valueText + "']").attr("value"); // Getting the value of the option to select in the list lookup

yourControl.val(value); // Setting the value of the list lookup control

yourControl.parent().find("input").val(valueText + "#--#" + value);  // As setting the value of the list lookup control is not enough to be taken into account by the Nintex Forms, another value has to be set:it's the value of an hidden input which should have a specific format

NWF$(NWF$(this).parent().find("input")[1]).val(value); // This is a mistake: you don't need to add this line

Don't hesitate to ask if it's not clear

Translate

Forum|alt.badge.img+9
  • Nintex Partner
  • Apr 5, 2018 5:56 PM UTC

In the list lookup, does the option with this title still exist "EN ENGLISH"?

It doesn't seem to find the value corresponding to the title "EN ENGLISH".

If you're executing this script when the form loads, I advice you to use this script to be sure that it's executed when the list lookup has been loaded (maybe your script is executing when the list lookup is not loaded and doesn't have any option):

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

setDefaultValue();

});

 

function setDefaultValue(){

var valueText = "EN ENGLISH";

var yourControl = NWF$("#"+yourControlId);

if(yourControl.parent().find(".nf-lookup-loading").length > 0 && yourControl.parent().find(".nf-lookup-loading")[0].style.display != "none") {

setTimeout(setDefaultValue,200);

} else {

var value = yourControl.find("option[title='" + valueText + "']").attr("value");

yourControl.val(value);

yourControl.parent().find("input").val(valueText + "#--#" + value);

}

}

Hope this helps

Translate

Forum|alt.badge.img+9
  • Nintex Partner
  • Apr 5, 2018 6:02 PM UTC

Thanks a lot for this, it works really great

Translate

Forum|alt.badge.img+7
  • Novice
  • Jul 10, 2018 4:22 AM UTC

What does ko.dataFor refer to? The knockout.js library? How does this work or is enabled for use with Nintex forms?

Translate

Forum|alt.badge.img+4

Yes it is knockout.js and it is loaded by Nintex Forms

They use it for lookup list field

Translate

Forum|alt.badge.img+7
  • Novice
  • Jul 18, 2018 1:17 AM UTC

Is the use of knockout.js documented anywhere within Nintex help and/or encouraged for use? Also, if Nintex decide to change to a different javascript library, then anything using knockout would cease to function. So something to be wary of I guess?

Translate

Forum|alt.badge.img
  • Jun 11, 2019 8:14 AM UTC
worked perfectly for me.
Translate