JavaScript CookBook/Workflow Form/Execute an action whenever the value of a certain form field changes

From GeoMedia Smart Client
Jump to: navigation, search
GMSC 2013/2014 Javascript API Overview Form Events Types Utility Functions client-side Validation Conditions Interaction with SmartClient Cookbook Cheatsheet


Execute an action whenever the value of a certain form field changes

Problem: You want to react to the value changes of a specific <FormField> and execute an action whenever this change happens

Solution: Every time the user changes the value of a form field in the user interface, its .value() observable is updated. You can subscribe to these changes by using the .subscribe() method provided by Knockout.js

The following example emits a message to the Javascript console every time the value of FORM_FIELD changes:

IG.vent.on('form:ready', function(form){
   form.getItemById('FORM_FIELD').value.subscribe(function(newValue){
       console.log('FORM_FIELD value changed to' + newValue);
   });
})

Other Recipes in this category: