Solved

How set a variable Nintex Forms with Javascript


Badge +1

I wish to be able to set the value of a NintexForms variable with Javascript.


I found an article on this subject wich mentions the following code.

NWF$('[data-controlname*=FormVariableName] input').val()‍;

 

I’ve tried this but it’s doesn’t work

NWF$('[data-controlname*=myVar] input').val(“hello”)‍;

Can someone help me ?

🙂

icon

Best answer by MegaJerk 10 May 2024, 08:20

View original

4 replies

Userlevel 5
Badge +14

We’ll need some more details. Are you using Classic, Responsive, or New Responsive forms?

Also I’d like to know a little more about what you’re trying to accomplish. I’ve posted before about how to update a Form Variable using js but it’s almost never something that I’ve ever needed to do in production. It will be helpful to understand your situations a little better.

 

 

Badge +1

Good evening,
Thanks for your feedback.

In fact I use a classic form as part of a tutorial which aims to perform a page switch in a form.

function goStep(stepNumber)
{
var hiddenTxtBox = NWF$("#"+hiddenTxtBoxId);
hiddenTxtBox.val(stepNumber);
NWF.FormFiller.Functions.ProcessOnChange(hiddenTxtBox);
}

The code above implies that the text field is used as a "hidden" element in order to be evaluated by a rule.
However it remains visible on the layout which is not very "clean" and I was wondering if it was possible to directly access a form variable?

Userlevel 5
Badge +14

the code he makes for goStep is only going to work at targeting a Form Control that has been assigned a JavaScript ID in the advanced settings. You’d need to change the function to look something like this:

function goStep(stepNumber)
{
var hiddenTxtBox = NWF$("[data-controlname='hiddenFormVar'] .nf-calculation-control-value");
hiddenTxtBox.val(stepNumber);
NWF.FormFiller.Functions.ProcessOnChange(hiddenTxtBox);
}

 

where the data-controlname equals the name of your Form Variable proper.

 

That should roughly make the function work.

Badge +1

It's top class !
Many thanks for your help, it works very well and is very clean as well.


Have a nice day😉

Reply