Javascript API

From GeoMedia Smart Client
Revision as of 10:28, 29 June 2012 by Fbuching (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The Workflow Javascript API is a Javascript library that allows you to manipulate your workflow forms "on the client side" (i.e. in the user's browser). This allows you to:

  • access items of the form and manipulate them (e.g. show/hide/remove)
  • serialize and submit the entire form or parts of it to the server
  • embed dynamic, user-driven form actions in your workflow

Typical use cases for this API include:

  • you want the workflow form to respond to user actions (e.g. hide the "Post Address" form group if the user clicked the "Notification: Email" checkbox)
  • you want to write custom form field rules, that validate user input on the fly (e.g. an advanced password validator that ensures the entered password consists of more than two uppercase letters)

Getting Started

Embed a custom script in your workflow

   <Form name="CUSTODY" table="CUSTODY" idfield="GUID" customscript="~/MyCustomFolder/CustomScript.js">

Your first customscript{   // is triggered once the form was initialized
     var sampleField = IG.form.getFieldById('sampleField'); //access the "sampleId" field with the IG.form.getFieldById function
     sampleField.addEvent('blur',function(){ //add an event to the Formfield
	alert('You just entered "' + sampleField.getValue() + '" into sampleField')

Your first custom validator (coming soon)

describes the writing of a validator

Form API Reference

Base methods for all form items

IG.FormItem provides an abstract base class for all form items in an IGForm (the form itself, form groups, form fields).

Method description
.show() shows the item (and all its sub-items)
.hide() hides the item (and all its sub-items)
.toggle() toggles the item (and all its sub-items)
.disable() disables the item (and all its sub-items)
.enable() (re)-enables the item (and all its sub-items)
.serialize() serializes the value of the item into a query string (e.g. <input type="text" name="FIELD_ID" value="foo"> --> &FIELD_ID=foo).
.isValid() validates the item against the preconfigured validators (see below) and returns true in case of a successful validator, false otherwise
.validate() like isValid(), but displays error messages in the UI
.getValue() returns a JSON value of the item
.submit(url, method, callback) POST). The optional callback is executed when the server response arrived
.remove() removes the item and all its sub-items
.addEvent(event, cb) adds event to the form field (see event section below), cb is a callback function that is invoked upon the event occurs
.removeEvent(cb) removes the event to which the callback function was bound
.removeAllEventsEvent([type]) removes all events, the optional parameter type allows the restriction to one event type (e.g. "click" for all click-Events)