Watching/Tracking Fields

Watching fields can be used to monitor changes within a form filling field and taking specific actions when those fields are changed.

Note:    Adding this to a field replaces previous watch functionality.

watchField

Since version 9.0

Method

sfjs.watchField(fieldNameOrId, callback, runOnStart, onChangeOnly);

or

sfjs.bindWatchField(fieldNameOrId, callback);

Parameters

fieldNameOrId—The name or ID of a field (case sensitive).

callback—Name of custom function that binds to the field.

runOnStart—Set to true to force the custom function to execute immediately after binding to the field (optional).

onChangeOnly—Set to true to bind the custom function to only execute on change (optional).

Remarks

An advanced method for binding a field and a custom function. Binding fields to custom functions allows for any possible action to be taken when interacting with a field.

Can be used on any field type except HTML Literal.

If used more than once on the same field, only the last applied binding will be used. To apply multiple bindings on the same field use the bindWatchField() variant instead.

Custom functions may be written inline if preferred.

An argument containing the bound field’s ControlDefinition will be sent down to your custom function for reference. This can be used to instantly get the field value and other useful properties.

Example

//create custom function to bind

function myCustomFunction(fieldController){

   var fieldValue = fieldController.FieldValue;

   if(fieldValue == "Some Value"){

alert("Field has some value");

}

}

//Binds custom function to Title field

sfjs.watchField("Title", myCustomFunction);

//Binds custom function to Title field, on change only

sfjs.watchField("ff_Title", myCustomFunction, true);

//Binds function on top of previous watch function instead of replacing it

sfjs.bindWatchField("ff_Title", myCustomFunction);