Creating Menus Dynamically
- Last UpdatedJan 09, 2024
- 1 minute read
You can create new menus from within your appware dynamically using the form method NewMenu().
For example, you could equip your form with the methods popupCreate() and popupAction() which would allow you create and service a popup menu from an array of strings.
Executing !this.popupCreate(‘NewPopup’, !fieldArray) will create a new popup menu and assign it to the form.
define method .popupCreate( !name is STRING, !fields is ARRAY )
--!fields is an array of field name strings
!menu = !this.newmenu( !name, ‘popup’ )
--add all the fields with same open callback
do !n from 1 to !fields.size()
!menu.add( 'Callback', !fields[!n], '!this.menuAction(' )
enddo
-- assign the new menu as the form’s popup menu
!this.setpopup( !menu )
endmethod
define method .popupAction( !menu is MENU, !action is STRING )
-- General popup menu action routine
if ( !action eq ‘SELECT’ ) then
!name = !menu.fullname()
!field = !menu.pickedField
-- execute application actions according to the field selected
$P selected field $!field of menu $!name
...
else
-- execute applications for unselected field (toggle)
...
endif
endmethod