Hi guys,
I know this has been already talked about but I can´t seem to find the issue with my code.
I have the following function which takes a client id javascript variable (from nintex forms) and a lookup id and sets the control.
function setDropdownLookupValue(control, lookupId) {
//If 0 is passed, use the SelectValueMask as option value to look for
const option_value = lookupId > 0 ? lookupId : NWF.FormFiller.Functions.SelectValueMask;
// Nintex selects a hidden input field when accessing the lookup via js variable
const hiddenInput = NWF$("#" + control);
// By replacing the _hid by nothing, the selector will give us the choice field
const choiceId = control.replace("_hid", "");
//"Unselect" each option in the dropdown
NWF$(`#${choiceId} option`).attr("selected", false);
//Store the correct choice field by value
const choice = NWF$(`#${choiceId} option[value='${option_value}']`);
//Select it
choice.attr("selected", "selected");
//Read data-nfchoicevalue which contains the value we want to set the hidden input to
const hiddenInputValue = choice.attr("data-nfchoicevalue");
hiddenInput.val(hiddenInputValue);
}
And I have a list which looks as follows:
Title : Id
I then create a lookup column to that list and add it to Nintex Forms.
With my function, I can set the lookup field, until I want to set the lookup field again to the same value. So if I am running the following in Chrome Dev Tools
setDropdownLookupValue(lookup,1)
The value gets changed to the item with id 1 (A)
If I use the code to set the lookup to 2, the value gets changed to item with id 2 (B).
When I then want to reset it to 1, it changes to "Please select a value".
I could then set the lookup to any value which is not 1 or 2 (or other used ones), as the already "used" ones all point to "Please select a value".
If I click save, the value of A (id:1) is saved to the list item.
Anyone got an idea what I need to change to be able to select the same value again?
Thanks!
Nintex Forms Version:
