Tutorial Chapter 5: Enhancing the Form |
A combobox defines a dropdown box of values, allowing the user to select a value for the underlying formfield.
In this example application the only valid values for the state column of the database table customer are IL, IA, and WI. The form item used to display the state field can be changed to a COMBOBOX displaying a dropdown list of valid state values. The combobox is active during an INPUT, INPUT ARRAY, or CONSTRUCT statement, allowing the user to select a value for the state field.
Figure 1. A form with a combobox
The values of the list are defined by the ITEMS attribute:
COMBOBOX f6=customer.state, ITEMS = ("IL", "IA", "WI");
In this example, the value displayed on the form and the real value (the value to be stored in the program variable corresponding to the form field) are the same. You can choose to define different display and real values; in this example, the values Paris, Madrid, and London would be displayed to the user, but the value stored in the corresponding program variable would be 1, 2, or 3:
COMBOBOX f9=formonly.cities, ITEMS=((1,"Paris"),(2,"Madrid"),(3,"London"));
Although the list of values for the combobox is contained in the form specification file in this example program, you could also set the INITIALIZER attribute to define a function that will provide the values. The initialization function would be invoked at runtime when the form is loaded, to fill the combobox item list dynamically with database records, for example.