Omnis Technical Note TNJC0002July 2013

JavaScript Components: Subform control

for Omnis Studio 6.0 or above

The Subform control allows you to place another remote form inside the main remote form; the concept of the subform is similar to embedding an iframe into an HTML page where you can embed another form or page. You could, for example, create a single “main” form and a number of other remote forms loaded at runtime into a subform control, to create a powerful and interactive web application with many subforms or layers.

When you have placed the subform control on your remote form, you specify the initial remote form to appear in the subform in the $classname property. Alternatively, you can switch subforms at runtime by assigning a new remote form name to $classname to switch the current form displayed in the subform control, as follows:

; oSub is the name of the Subform control on the main Remote form
Calculate $cinst.$objs.oSub.$classname as NewFormName

The Holidays sample app uses a subform to display either the User or Admin form. To try the app, download a trial copy of Omnis Studio 6.x, click on the New Users button in the main Omnis toolbar, click on the ‘Explore Applet Libraries’ button, and open the ‘Holidays’ app. When the main jsHolidays remote form is loaded, its $construct() method calls a class method to setup the initial subform to be shown which, in this case, is the User form. In addition, there are buttons on the main Holidays form to allow the end user to switch forms; for example, the code behind the User button is:

; $event method for User button on jsHolidays
On evClick
Do method setSubForm (kUserForm)
Calculate iAdminBtnState as kTrue
Calculate iUserBtnState as kFalse
Do $cinst.$objs.adminBtn.$enabled.$assign(kTrue)
Do $cobj.$enabled.$assign(kFalse)

The setSubForm method has the following code to switch forms:

If pOption=kAdminForm ;; test if Admin or User
Do $cinst.$objs.subForm.$classname.$assign("jsAdminForm")
Do $cinst.$objs.subForm.$classname.$assign("jsUserForm")
End If


If the $multipleclasses property is enabled, the previous remote form is cached and hidden on the client, otherwise the remote form instance is destroyed. If any previous remote forms have been cached in this way using $multipleclasses, you can switch back to them instantaneously, otherwise they have to be reloaded each time you assign to $classname of the subform object.

Note you can also create subforms dynamically in a 'Subform Set' (a new feature in Omnis Studio 6.x) which is described in tech note TNJC0006.

Click here to download a trial copy of Omnis Studio 6.x and try out the Holidays app. Or you can visit the JavaScript Apps Gallery to try out further components.