Nintex for SharePoint Forum
Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
Showing results forÂ
When I open a new form, I want to set the default value of my dropdown to the first value of a list (indexid = 1) and it should also be saved ( as long as the user doesnt change the value) when the user clicks on the "Save" button. I tried it with code below, but nothing happened Nintex Form version 2.9.3.1.
dlookupID is the JavaScript variable name of my dropdown.
NWF.FormFiller.Events.RegisterAfterReady(function () {
setLookupFields();
});
function setLookupFields() {
// Getting view model of my lookup field dropdown control
vmForApplication = ko.dataFor(NWF$("#" + dlookupID)[0]);
// Setting value to drop down
vmForApplication.initialValue = "1";
}
Solved! Go to Solution.
Since we upgraded to Forms version 2.10 (from an older version like 2.5) we have had a lot of trouble with this. The following code works for me but it isn't as clean as I would like it to be so if anyone has a suggestion for improvement, JS is not my specialty! There are two issues in my opinion:
As I said, it works, it is just a little ugly. Note that if you are not dealing with the parent/child relationship you can hardcode default value really easily:
NWF$(document).ready(function() {
NWF$("#" + myddl).val('3');
});
Here is the parent/child one:
NWF$(document).ready(function() {
NWF$("#" + ddlParent).change(function () {
NWF$("#" + ddlChild).change();
});
NWF$("#" + ddlChild).change(function () {
var ddlChildId = ddlChild.substring(0, ddlChild.length -4);
var len= NWF$("#" + ddlChildId ).find("option").length;
if(len>=2) {
return delay(1000).then(function() {
NWF$("#" + ddlChildId).prop('selectedIndex',1);
NWF$("input#" + ddlChildId).val(NWF$("#" + ddlChildId).find("option")[1]);
});
}
else {
while(i<10 && len==1) {
i++;
return delay(1000).then(function() {
len= NWF$("#" + ddlChildId ).find("option").length;
if(len>=2) {
NWF$("#" + ddlChildId).prop('selectedIndex',1);
NWF$("input#" + ddlChildId).val(NWF$("#" + ddlChildId).find("option")[1]);
}
});
}
}
});
function delay(t) {
return new Promise(function(resolve) {
setTimeout(resolve, t)
});
}
});
Hi Ann,
Your script worked, but does not write the value of the child to the XML in a repeating section. Adding .change() fixed it.
i.e.NWF$("#" + ddlChildId).prop('selectedIndex',1).change();
The other problem is the script only works on the first item of a repeating section. How can we get it to work items that are subsequently added?