How to use onUserchangeValue(function fn) { } ?

Sanjay Bagri1
Tera Guru

Hi ,

Please  can you give me the scenario for the use of this script: 

onUserChangeValue(Function fn) this function how to use and where

var handler = function(fieldname, originalValue, newValue) {
  console.log('The field ('+ fieldname + ') has a new value of: ' + newValue); // function code
}
 
var unregister = g_form.OnUserChangeValue(handler);
 
// To unregister the event listener
unregister();

Please help me .

waiting for your response .

Thanks 

 

2 REPLIES 2

Shelby2
Giga Expert

This is triggered when a user makes a change on a form.

So in onUserChangeValue(Function fn) - the "Function fn" portion is, in the code above, the handler function.

The handler function passes in 3 values, the field name, the old value and the new value. The return of the function, so the console log, is then passed into the g_form.OnUserChangeVaule() and is unregistered.

 

Basically the use of this is to log changes to a form from a user. Stating the field name and the new value.

Changes from client scripts, UI policies, or any other non-user interactions, do not trigger the listener. On a user changing a value on a form can trigger this.

 

Please mark helpful or correct depending on the impact of my response.

 

learn nv
Tera Contributor

Hi Shelby,

 

Where shall we define this function? This function need to be defined in a UI Script or client script or as an event or etc..to recognize the changes done to a form?