Skip to main content
Nintex Community Menu Bar

Custom JS in Form Settings strips CR LF (on prem 2019)

 

All,

 

Looking for some clues.

 

When entering JS into the Form Settings section of a form, after pasting the text into the field, many of the carriage returns and line feeds are stripped from the entry.   This is seen upon re-opening the form settings.

 

When there are // comments in the JS code, this creates HUGE problems in that the code won't run since comment lines may extend forever.

 

Additionally, this makes it a TOTAL PAIN to read the code in that box - or even copying to another editor -- as it all needs to be reformatted.

 

Thoughts?

 

Thanks,

 

jeff

 

HEXEDITOR Dumps of before and after below:

 

26898i967EA0DDDBFF31F1.png

 

 

My recommendation is to just use:



/* comment */

 



Instead of:



// comment

 



A bit of a pain in the butt if you're used to strictly using // everywhere (or use any sort of linter), but working with JS in Nintex Forms is a matter of compromises that one must become accustom to.



 



For instance, the following code when placed in the Custom JS section of your form settings will *also* cause issues:



NWF$(".nf-repeater-row:not(.nf-repeater-row-hidden)");

 



Despite being a totally valid way of targeting every visible Repeating Section Row on the form, it will create an error because Nintex does a check to see if any of the custom JS (anywhere that is not a referenced library in the Form's Advanced Settings section) contains function calls that *look* like their Runtime Function calls (as seen in the Runtime Functions tab of any formula builder), and will change them to make a call to those internal Runtime Functions when the form is compiled for SharePoint. 



 



This results in the above code changing to something along the lines of:



NWF$(".nf-repeater-row:NWF.RuntimeFunctions.not.call(someFunctionToGetAControlValue(), .nf-repeater-row-hidden)");

 



Note that this is regardless of whether or not you've made a purely js function call to something that falls into their category of sharing a name with one of their RuntimeFunctions. It will also happen to the following code:



NWF$(".nf-repeater-row").not(".nf-repeater-row-hidden");

 



The only way around this is to make your code not match whatever regex they're using to parse it with, and the easiest way I've found to do that is to add a space between the function's name and the open parenthesis:



NWF$(".nf-repeater-row").not (".nf-repeater-row-hidden");



// Or, in the case of when the offending:

// functionName(

// Is inside of a jquery selector string

// and can't have an extra space, then you

// just have to physically move them apart



NWF$(".nf-repeater-row:not" + "(.nf-repeater-row-hidden)");


 



So yeah, there are a few oddities and quirks working with JS in Nintex Forms, but you should be able to work around most of what you'll encounter with a little time, or by asking around here! 



 



I hope this helps 


use Shift-Enter to add line breaks to the code.


Reply