Toggle menu

helper.utilExpandJSONTemplate(template)

Takes a string and replaces any markers in it with the current value of a referenced field or variable. Also escapes JSON.

Markers are in the form #FIELD# and %var% where FIELD is the name of a field and var the name of a form variable.

Any JSON supplied to the template will be escaped.

Repeating Pages

If the field you want to display the value of is on a repeating page, include the page instance in square brackets between the hash symbols, like this #NAME[1]#.

The following tokens can also be used:

  • #PAGEINSTANCE# - The page instance that's currently being displayed (zero-based, ie the first instance is 0)
  • #PAGEINSTANCEDISPLAY# - The user friendly current page instance (one-based, ie the first instance is 1)
  • #PAGEINSTANCEMIN# - The minimum number of instances set in the forms designer
  • #PAGEINSTANCEMAX# - The maximum number of instances set in the forms designer
  • #PAGEINSTANCECOUNT# - The current number of instances (of this page) that have been generated

Arguments

ArgumentTypeDescription
templateString, requiredThe template text

Returns

A JSON escaped string.

Example

The following function has been added to the first text input box, called FIELD. myVar is a form variable with the value "hello".

function (helper, fieldName, value, valid, eventName) {
    if (eventName == 'CHANGE') {
        var msg = helper.utilExpandJSONTemplate('#FIELD#, %myVar%');
        helper.setFieldValue('MESSAGE', msg);
    }
}

Enter {"name":"value"} to see the escaping, or anything else you like, into the text box to see the result.

Share this page

Facebook icon Twitter icon email icon

Print

print icon