Add a toggle box to the window
- Last Updated: December 28, 2023
- 2 minute read
- OpenEdge
- Version 13.0
- Documentation
There are no LOGICAL fields in the Customer and Order tables
to display as toggle boxes, but you can add a variable to display as a toggle box
instead.
- Select the Toggle Box icon from the Palette.
- Click in the design window to the right of the Total Ext price field to drop the toggle box onto the window.
- Change the Object name to lShowWarehouse (starting with the letter l because it is a representation of a LOGICAL variable) and change the Label to Show Warehouse Info.
- Adjust the size of the toggle box to show the whole label.
- Go into the property sheet for the toggle box, click the Advanced button, and change its initial value from no to yes.
- Select the Edit Code icon and define this
VALUE-CHANGEDtrigger for the field:DO: ASSIGN lShowWarehouse. IF lShowWarehouse THEN ASSIGN cWorstWH:HIDDEN = NO cBestWH:HIDDEN = NO. ELSE ASSIGN cWorstWH:HIDDEN = YES cBestWH:HIDDEN = YES. END.
Remember that a field value entered on the screen does not get saved to the record buffer
until it is assigned. Therefore, the trigger block has to start with an
ASSIGN statement for the variable before you can refer to its
value. Alternatively, you could query the SCREEN-VALUE attribute of the
field without assigning it. When you reference the SCREEN-VALUE,
however, the value is represented as a character string, even though it is not displayed
that way, so you would have to explicitly compare the SCREEN-VALUE to
YES or NO like this:
|
By contrast, when you assign the value to its record buffer, you can refer to it as a LOGICAL so that it becomes in effect a one-field expression that evaluates to true or false:
|
Your new trigger is setting the HIDDEN attribute of the two
warehouse-related fields to true or false. When you run the procedure and click the
toggle box, the fields appear and disappear:
Look at the code to define a toggle box
This is the DEFINE VARIABLE statement the AppBuilder generated to
define this toggle box (you can see this code from the Code
Preview window):
|
The INITIAL value, LABEL, VIEW-AS
type, and SIZE are all defined here. As with other fields, the
toggle box is enabled not by syntax in the DEFINE VARIABLE
statement, but because it is added to the ENABLE statement in
enable_UI.