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
Argument | Type | Description |
---|---|---|
fieldName | String, required | The name of the field to be updated |
fieldValue | String, required | The new value of the field |
pageInstance | Integer, optional | Used 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;
}