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
May I know what is [1] referring to?
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 h1] ? is it the list item id of the particular item ?
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);
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
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("optionntitle='" + 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")t1]).val(value); // This is a mistake: you don't need to add this line
Don't hesitate to ask if it's not clear
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("optionntitle='" + valueText + "']").attr("value");
yourControl.val(value);
yourControl.parent().find("input").val(valueText + "#--#" + value);
}
}
Hope this helps
Thanks a lot for this, it works really great
What does ko.dataFor refer to? The knockout.js library? How does this work or is enabled for use with Nintex forms?
Yes it is knockout.js and it is loaded by Nintex Forms
They use it for lookup list field
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?
worked perfectly for me.