We have a requirement to set the value of a dropdown based on a user. We are using calculated field to get the userprofile and on load, we set the dropdown based on this calculated value.
Currently, we are able to select the entry by binding a function after NWF.FormFiller.Events.RegisterAfterReady - my codes are shown below.
ddlDepartment is the javascript variable for my dropdown
preparedByDepartment is a calculated field
NWF$("#" + ddlDepartment).change(function () {
SelectDropDown(ddlDepartment, NWF$("#" + preparedByDepartment).val())
});
function SelectDropDown(dropdown, selection) {
NWF$("#" + dropdown + " > option[title='" + selection + "']").prop("selected", true);
}
After execution, the correct option is selected, but on saving, it shows blank.
Appreciate any help.
PS - I've tried the solution here Set default value to lookup field stopped working after Nintex Forms 2013 latest update but doesn't work for my case.
Try trigger focusout for control or call ProcessOnChange after correct option is selected:
ctrl.trigger("focusout");
or
NWF.FormFiller.Functions.ProcessOnChange(ctrl);
Didnt work
I managed to solve it following this thread Nintex form rule doesn't fire when select dropdown is changed via JavaScript
This solved my problem
yourControl.parent().find("input").val("yourNewValue")
Use .change().
NWF$("#" + dropdown + " > option[title='" + selection + "']").prop("selected", true).change();