to set default value during form load you should rather use
fyValue.initialValue = currentYear.Value;
however, I'm not sure whether it still works with recent changes of lookup functionality
Thanks Marian! But the problem with the newer version is that ko.dataFor(NWF$("#" + ddlFYLookupId)[0]) is undefined.
And even with the previous version, fyValue.initialValue didn't work because by the time my REST call to get the financial year completes, the dropdown was already filled with values and didn't consider initialValue.
Regards,
Amal
Hi Michael,
Unfortunately, No. I just reverted back to the older version, in which below works:
var fyValue = ko.dataFor(NWF$("#" + ddlFYLookupId)[0]);
fyValue.selectedItem(currentYear.Value);
Amal
I am also having the same problem, updated from 2.9.0.0 to 2.9.3.0 and my functions stopped working.
function SetValueOnLookupControl (jvarCtl, CtlValue)
{
var yourControl = NWF$("#"+ jvarCtl);
var value = yourControl.find("option[title='" + CtlValue + "']").attr("value");
yourControl.val(value);
yourControl.parent().find("input").val(value);
NWF.FormFiller.Functions.ProcessOnChange(yourControl);
}
Is there any technical doc or SDK for the new release. Kind of stuck now.
Hi guys, because Nintex is an ever evolving product, I'm not sure the "JS" tricks we can do at the moment will ever be "future-proof". You'll see in release notes sometimes warnings about "JS" may have been changed or affected by an update. I'm going to mark this closed out for the solution that worked at the time of the posting.
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:
- I'm not able to catch the change event of the child control as I should be. I have to trigger the change from the parent manually
- When the change happens it is too fast so I have to put in a delay loop to wait for the DDL to load completely. Seems like there should be a better way.
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 Mike,
Of course it's great Nintex continuously improves their products. But would it be possible to:
- with new/major updates provide a list of controls which are affected with regards to custom JavaScript? Even better if you could describe for common actions what the new custom js would look like.
- obviously from the posts in this and other forums there seems to be a customer requirement for additional control functionality.
Today I figured out a way to set a lookup dropdown list using JavaScript with only a few lines of code and working in NF 2013 2.10.0. As a base for the code below I created a form with 2 lookups to a Currency list. Goal is to set the selected dropdown value of the 2nd one with the selected value of the 1st:
// First Dropdown - has JavaScript Client ID jsCurrency
var currencyCtrl = NWF$("#" + jsCurrency);
var currencySelection = currencyCtrl.val(); // Result as lookup string, e.g. : 1;#EUR
var selectedCurrency = NWF.RuntimeFunctions.parseLookup(currencySelection,true); // Lookup value itself : EUR
// Second dropdown - has JavaScript Client ID jsSecondCurrency
var secondCurrencyCtrl = NWF$("#" + jsSecondCurrency); // this returns the input element
var selectCtrl2Id = jsSecondCurrency.replace('_hid',''); // determine id of select element
var selectElement = NWF$("#" + selectCtrl2Id); ; // this returns the select element
NWF$("#" + selectCtrl2Id + " option:contains(" + selectedCurrency +")").attr("selected", true); // set select to specific lookup value
secondCurrencyCtrl.val(currencySelection); // also store lookup string in input element
As mentioned this works now in two different libraries.
Does somebody has a clue why this code bellow doesn't work in Forms version 2.10 ? It used to work till recent upgrade
Error: "ko" is not defined
It's about passing a value to a lookup filed from an URL string.
NWF.FormFiller.Events.RegisterAfterReady(function () {
setItemId();
});function setItemId() {
var itemId = fn-GetQueryString('LookupId');
if (Number(itemId) > 0) {
var ddItem = NWF$('#' + inputItem);
var vm = ko.dataFor(ddItemr0]);
vm.initialValue = itemId;
}
}
It seems that if I start with a (document).ready event for the same purpose (of course the code is a bit different then as shown bellow), I have a hard time running the rest of the code with some AJAX / REST calls etc,; in this case these are fired as soon as lookup filed (another one) is selected, instead after the submit function.
NWF$(document).ready(function () {
setItemId();
});
function setItemId() {
var item_Id = getParameterByName('LookupItem');
if (Number(item_Id) > 0) {
NWF$('#' + inputItem).val(item_Id);
}
}
Thanks for any suggestion!
Hi David,
My conclusion was that Nintex may have changed the setup of the List Lookup control in one of their updates; the control is a combination of (2 <input>) HTML elements which seem to have been re-arranged. As such previous JavaScript code no longer works. Have a look at my code to see if is of any help resolving your issue.
BR
That's a ridiculous argument, virtually all software solutions evolve and change. How that change is managed defines a professional approach from rank amateurs (Nintex). Nintex changed a software feature with a dependency effectively redefining the interface, haven't bothered to clearly notify their client base let alone give clear examples of how the change required should be implemented.
Nintex are a ****** shower of an organisation. We've come to the conclusion Nintex can't be trusted with even remotely business critical solutions.
Using Nintex Forms 2013 v2.11.1.11 (Jan 2018) the following statment works to set the value of a Choice field drop-down list in a Nintex form:
NWF$('#' + fieldId).val(fieldvalue).change();
Note: the .change() updates the selected value in the choice control AND triggers the recalculation of any calculated value fields tied to the Choice drop-down list value.
Took me many sets of trial and error to see what would work for this since my updated Nintex version (which affected Javascript according to the Release notes).
Hope this helps.
Hi David,
The above mentioned "fieldId" , is it a javascript control name or the field name itself connected the control.
It is the javascript ID name you assigned to the control in the Advanced section of the control properties.
And in runtime it contains the actual control DOM id, which may look like the following example: ctl00_ctl38_g_284b4677_5f42_4a00_bf38_f9516134732b_ctl00_ListForm1_formFiller_FormView_ctl18_ctl16_ctl16_86f210d1_ee13_49e5_9d79_cd44f49ef84f
Thanks, I have Nintex Forms 2013 v2.11.1.0 and it seems it is working.
Sorry it seems NOT working
Hi David,
Either Nintex changed in Nintex 2013 Forms v2.11.2.2 again, or I'm doing something wrong, but it does not seem to work for me. Would this also update the control itself and show a checked box for the set choice?