Create forms dynamically

Dynamic dialogs are typically used with forms that are generated at runtime.

Purpose of dynamic forms

Before you instantiate a new ui.Dialog object, you must load an existing compiled .42f form, or create a new form dynamically in your program.

Since dynamic dialogs are build at runtime (because form fields are not known at compiled time), the corresponding form is also created (or completed) at runtime.

Note: The current form (in the current window) is automatically attached to the new created dialog.

Dynamic form creation with createForm()

Forms built at runtime must be created with the ui.Window.createForm() method, and must contain a valid definition with layout containers, form fields, and screen records.

Note: See Genero BDL demos for a complete example of form creation at runtime.

The createForm() method will be invoked by using the current window. For the main form of the program, use directly the (empty) SCREEN window. For child windows, create the windows without a form by using following syntax:

OPEN WINDOW w1 WITH 1 ROWS, 1 COLUMNS

Assuming that there is a current empty window, you can then create the ui.Form object, to finally get the om.DomNode object to build your form:

DEFINE w ui.Window,
       f ui.Form,
       n om.DomNode
LET w = ui.Window.getCurrent()
LET f = w.createForm("myform")
LET n = f.getNode()
...

Use om classes, to build your form dynamically. A good practice in creating dynamic forms is to write first a .per file, that implements a static version of one of the forms you want to build at runtime. Compile the .per to a .42f and inspect the generated XML file, to understand the structure of the form file.

COMBOBOX initializers

Combobox initializers are called when executing the DISPLAY FORM or OPEN WINDOW WITH FORM instructions.

When creating a form dynamically with COMBOBOX fields, the initialization functions are not called. The combobox items must be created as part of the combobox node.