Toggle menu

helper.setFieldValue(fieldName, fieldValue [,pageInstance])

Updates the value of a field.

This function behaves slightly differently depending on where it is used.

When working client-side setFieldValue will only update the value of a field on the current page of the form. Modifying the value of a field will trigger the execution of any handler property defined on the field.

Server-side you can target a field on any page of the form that already exists in the session. It's not possible to update fields on future form pages that have not been visited yet as these pages and fields don't yet exist. The targeted field's handler will not be triggered (because handlers are only triggered client-side).

If a page repeats, and there is more than one instance of it, the pageInstance that holds the field you'd like to update should also be supplied.

Executed

Client-side and server-side.

Arguments

ArgumentTypeDescription
fieldNameString, requiredThe name of the field to be updated
fieldValueString, requiredThe new value of the field
pageInstanceInteger, optionalUsed with repeating pages.

The instance (zero-based) of the page the field is on that you'd like to update. Defaults to the current page instance if called on the repeating page that holds the field. If you call this function from elsewhere on your form and the page instance is not supplied, the update will fail

Example

In this example setFieldValue is used in a field handler and combined with .getVariable to update 'FIELD4'.

function (helper) {
  helper.setFieldValue('FIELD4', helper.getVariable('myVariable'));
}

This example has been added to the next function of a wizard button. It updates the value of a field on a page that has just been visited.

function(helper, defaultPage, sessionData) {
    helper.setFieldValue('FIELD2', 'A new value');
    return defaultPage;

Last modified on September 13, 2023

Share this page

Facebook icon Twitter icon email icon

Print

print icon