cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
harryr
Nintex Newbie

Print a JS var value to a single line text box (Nintex Forms)

Jump to solution

Hi All

I have what I hope is a very simple question (Nintex Forms). I want to update a single line text box with a string value when a button is clicked.

Example: 

Button Client Click: updateBox()

Text box name(Client ID JavaScript variable name): riskBox

Custom JS: 

NWF$(document).ready(function() {

   var testValue = "A";

         function updateBox() {
         document.getElementById("riskBox").value = testValue;
}
});

The problem is that it isn't working. The text box on the form doesn't update with the string value in testValue, which should be "A".

The other thing i have noticed is tha the button click causes the form to reload. I have "cause validation turned off and  button action : JavaScript.

This script is a simple test for something much bigger.

Any help would be appreciated.

As a bonus: If anyone can suggest how to make that text box non user editable (only by the scrip), that would be fantastic. Can HTML DIV's be inserted into forms?

Thank you

Nintex Forms version: 2013 (2.1022.0) SharePoint 2013

Labels: (1)
0 Kudos
Reply
14 Replies
emha
Nintex Newbie

Re: Print a JS var value to a single line text box (Nintex Forms)

Jump to solution

try following function

function updateBox() {
       NWF$("#" + riskBox).val(testValue);
}‍‍‍

form refresh might be caused by error in javascript or rules. check developer console for errors reported

As a bonus: If anyone can suggest how to make that text box non user editable (only by the scrip)

create a formatting rule with a formula that always evaluates to true and set the action to Disable

0 Kudos
Reply
harryr
Nintex Newbie

Re: Print a JS var value to a single line text box (Nintex Forms)

Jump to solution

Thanks for the code adjustment but I can't tell if it works because the page refreshes on the button press. I have checked the console and there are no errors being reported (probably because the page is refreshing). 

I tried this code adjustment applied to the Client Click Property from another thread that stops the page refreshing but doesn't trigger the change I want.

NWF$(document).ready(function() {
function updateBox() {
NWF$("#" + riskBox).value("HELP");
}
});

Again, no errors are reported in the console.

I have tested the standard JS code without Nintex wrappers in an HTML form and it works perfectly. 

A bit stuck here. 

0 Kudos
Reply
harryr
Nintex Newbie

Re: Print a JS var value to a single line text box (Nintex Forms)

Jump to solution

Just wanted to expand on my plans for this function.

I have written a javaScript function that I want to trigger on the button press. It does some evaluation of form fields and then calculates a result based on internal rules (in the script). It then outputs the result to a box on the form (not user editable). All this is done before the form is submitted and the workflow takes over to handle routing for approvals.

The function is pretty big and needs I believe should be stored in the Form Settings Custom JavaScript section. I need to call that function when the button is pressed to populate the result box.

Something I am having trouble understanding properly is how Nintex forms requires it's own wrapper function around custom JavaScript and when it should be used. From what I can see it is a function wrapper so I assume i can just write my entire function within that Nintex wrapper, then call it on the button press?

Do I need to call the Nintex wrapper function by a custom name instead?

Any help is appreciated.

0 Kudos
Reply
harryr
Nintex Newbie

Re: Print a JS var value to a single line text box (Nintex Forms)

Jump to solution

Calling the wrapper by a custom name didn't work. Do I need to create an onClick function for the button in the main JavaScript section?

If so how do I stop the button from refreshing the page?

UPDATE: So it looks like the chosen field values are being retained in the page reload but the function is't being fired.

0 Kudos
Reply
emha
Nintex Newbie

Re: Print a JS var value to a single line text box (Nintex Forms)

Jump to solution

place the function definition out of the ready() event handler, it not visible out of its scope.

....value('HELP')  should have been ....val('HELP')

0 Kudos
Reply
harryr
Nintex Newbie

Re: Print a JS var value to a single line text box (Nintex Forms)

Jump to solution

Hi Marian

Thanks again for your assistance, but it still doesn't work. 

The button properties are: 

The page reloads on the button press and there are no console errors reported. After the page refresh there is no value in the single line text box.

Am I still doing something wrong with the code or button properties?

Update: There is a syntax error reported when the page loads but it doesn't look related to my code:

Many thanks.

0 Kudos
Reply
emha
Nintex Newbie

Re: Print a JS var value to a single line text box (Nintex Forms)

Jump to solution

once again

place the function definition out of the ready() event handler, it not visible out of its scope.

ie, remove NWF$(document).ready wrapper and leave there just function definition.

Reply
harryr
Nintex Newbie

Re: Print a JS var value to a single line text box (Nintex Forms)

Jump to solution

Hi Marian

It's working now. 

Now it reads:

var formValue = "A";
function updateBox() {
NWF$("#" + riskBox).val(formValue);
};

The page no longer refreshes and the value populates. So this leaves me a bit confused. When do I need to use the "NFW$" and when do I not? 

I will try it with my larger code to check the functionality.

Thank you for your help.

Reply
emha
Nintex Newbie

Re: Print a JS var value to a single line text box (Nintex Forms)

Jump to solution

NWF$ just extends standard jQuery library

above simple example would work with pure jQuery reference like $('#'+riskBox)... or pure javascript code like document.getElementById("#"+riskBox)....

but in some more complex contructs that go deeper into nintex's internals you would need to use NWF$.

so it's 'safer' to get used to work with NWF$.

0 Kudos
Reply