The field has a css class "geoArea".
I've tried the following lines of code
NWF$('.geoArea select option[title="My option title"]').prop("selected",true);
NWF$('.geoArea select').val(optValue); //optValue is a variable with the numeric value of the option I want to select
With both lines I'm able to apparently set to field to the value I want but when I save the form, the value is lost, so if I open it again the field is blank again.
If I select the value manually in the field, the value is save correctly.
Do you know if is there anything else I have to set to save my value when I save the form?
Solved! Go to Solution.
thanks for your suggestion but it looks like the answers provided there don't solve my issue..
I've tried the setLookupFields approach but it doesn't set any value in my form and Wayne's method is the same I'me using (I've just definded the desired value before in the optValue variable).
Last method changes the value in the form but when I save, the value doesn't get saved..
Inspecting more in deep Kalpesh Vaghela method, I've found that in my case I had to do the following to correctly set the field:
var vmForApplication = ko.dataFor(NWF$(".geoArea select"));
calling it from a button (resp. once the form is already rendered) you need to use selectedItems, you are right.
if you needed to set default value during the form is initially rendered you would have to use initialValue.
maybe someone faces the same issue.
None of the suggested solutions worked for me. With my case the issue was that the Nintex form (SP 2013 on prem, v126.96.36.199) was adding _hid to the end of the lookup field ID in selected form variable.
In my case I had lookup field varibable name llMatGroup and in run time it resolved to
but the actual ID of the field in DOM was
When I changed this in the code all worked with normal
NWF$('#' + llMatGroup).val(idValueOfDesiredOption);
and then I used
NWF$('#' + llMatGroup).change();
to make sure selection is saved to the list
NO IDEA why this has happened and I am possibly the only one this ever happened or will happen to but I'll share this anyways.