cancel
Showing results for 
Search instead for 
Did you mean: 
Workflow Hero

Updating/Triggering Form Variable with JavaScript

Jump to solution

I'm looking for a way to trigger one or more Form Variables using JavaScript.

I did find an article with a comment by @azetuche (Re: Can i catch the form variables in javascript in Nintex forms ??) using the following code to set the value of a Form Variable:

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

but that's setting the value directly, and not exactly what I need.

I have several List Lookups as checkboxes on this form. When the checkboxes are selected, I have Form Variables running calculations. These are working great on their own.

I also have one unbound checkbox called Select All. When this checkbox is selected, I have JavaScript checking all of the checkboxes. Unfortunately, this action is not triggering the Form Variables to run their calculations. 

I've also unsuccessfully tried using the JavaScript from above, but using .trigger() instead of .val().

Additionally, I found Populate dynamically a calculated value by using a JavaScript function call‌ which uses

NWF.FormFiller.Functions.ProcessOnChange‍();

but that didn't work either because I'm not using Calculated Value fields, and I'd prefer not to.

Any help would be greatly appreciated.




SharePoint 2013 On-Prem | Nintex Forms & Workflow Enterprise
Labels: (1)
Reply
4 Replies
Workflow Hero

Re: Updating/Triggering Form Variable with JavaScript

Jump to solution

ProcessOnChange() expects to pass in a control/element which has been changed. so have you (correctly) passed in one of changed lookup checkboxes?

how do you make single checkbox checked? by directly setting its checked property?

if you did it by calling its .click() event, dependent calculations should be executed.

using the following code to set the value of a Form Variable

that's need not be very reliable.

at first, form variable might be recalculated out of your control by an indirect event. so despite you set it to some value, at some unknown point it might be recalculated to another value.

and at second, if you set its value by a javascript, it will not in turn cause to recalculate dependent formulas.

make the form variable rather dependent on an 'Sellect all' check box so that it recalculates on its change.

0 Kudos
Reply
Workflow Hero

Re: Updating/Triggering Form Variable with JavaScript

Jump to solution

You should be able to accomplish what you want simply by triggering a 'change' event on the inputs of type "checkbox". 

- Form -

All Controls: 

Control (1) : Yes/No: 

Control (2): Choice:

Control (3): Calculated Value:

Form Variable: 

Rules: 

Formatting for the Choice Controls: 

Custom Javascript

Copy  / Paste Code

NWF$("[data-controlname='checkAll_Toggle'] input[type='checkbox']").on("change", function(event){
  if (NWF$(event.target || event.srcElement).prop("checked")) {
    NWF$("[data-controlname='someChoices'] input[type='checkbox']").prop("checked", true).trigger("change");
  }
});

How does it work? 

It puts a "change" event handler on the 'Toggle All' Control. If you click on the toggle all control, it'll invoke the event handler. 

Once the event is being handled by our code, we check to see if the Toggle All is being set to On or Off (true or false). 

If it's true, then we get ALL of the inputs of type "checkbox" that are children to the "someChoices" control, and set them all to checked, and then trigger the change event on them, resulting in the form variable being updated, and the 'length' of the array being pushed to our Calculated Value Control immediately. 

So.... 

On Load: 

Two Items Checked: 

Check All Checked: 

I hope that this helps you accomplish what it is you're trying to do. 

Reply
Workflow Hero

Re: Updating/Triggering Form Variable with JavaScript

Jump to solution

This is EXACTLY why I love this community so much! Thank you!

This was what I needed to get this project completed by Monday. I really appreciate your help, and that you went the extra mile to build out an example, include screenshots (with highlights), include your code (with a copy/paste section), and fully explain the entire process. Now this can easily help others as well!




SharePoint 2013 On-Prem | Nintex Forms & Workflow Enterprise
Reply
Workflow Hero

Re: Updating/Triggering Form Variable with JavaScript

Jump to solution

I'm glad that it's going to help, and this is indeed a wonderful community! 

0 Kudos
Reply