Popupbutton object and info("trigger") issue

When choosing an option in a popupbutton menu, info("trigger") does not return the menu name

Menu..Set default truck

even though the popupbutton is named in the PopupButtonObject attributes panel, and the menu itself is named in the formula panel code:

menu("RunsPUM") +
menuitem("Set default truck","code","Call .Trucks")

No, it doesn’t, and it is not supposed to. The value in info(“trigger”) returns the name of the object – it tells you what object was clicked (you need to assign a name to the object if you want to be able to determine this). To find out what menu item was selected, you need to look at the value of the field or variable that is associated with the object, the Data variable.

The value in info(“trigger”) returns the name of the object – it tells you what object was clicked (you need to assign a name to the object if you want to be able to determine this)

The object that was clicked, the PopupButtonObject, had its name assigned in its Attributes panel.

Screen Shot 2020-09-16 at 1.48.58 pm

To find out what menu item was selected, you need to look at the value of the field or variable that is associated with the object, the Data variable.

Screen Shot 2020-09-16 at 2.07.48 pm

Stangely enough, selection of any menu item the did not update the contents of the data variable fRunsPUMchoice, which is why I was using info("trigger"). This doesn’t really matter as it turns out that info("trigger") does return the chosen menu item, as in my example.

None of this was expected behaviour, and I wonder if it has something to do with the use of the menu formula code.

It turns out that in a PopupButtonObject when menuitem( contains procedure code in the formula pane

menuitem("Set default truck","code","Call .Trucks")

this runs instead of any code in the object’s Procedure pane. Could it be that running this code also prevents assignment of the menu item chosen to the Data variable?

I think this is possible. At a minimum, any code defined in the menu formula will run before the PopUpButtonObject has finished processing. I would recommend not using code in menus associated with the PopupButtonObject. This feature (the CODE option) was designed for use with the regular menu bar.

The PopupButtonObject is really not designed for performing commands, as you are doing – it is designed for changing a data value. Basically a variation on using a bunch of radio buttons. You wouldn’t use radio buttons for a command like Set default truck.

If you want to perform commands from a popup menu, I would recommend using a shape object, an image object, or a text display object with a Font Awesome icon, and triggering the popup menu with the popupclick statement, or a variation.

I completely agree and in fact converted all of my P6 PopupButtonObjects to popupclick statements in text display objects in PX except for the odd couple that use submenus, which don’t work in popupclick statements yet. I have been able to get the PopupButtonObjects when working in this non-standard way using the CODE option with submenus, and this code should work with little modification in popupclick when it does support submenus.

Whenever I come up against undocumented or buggy issues like this (particularly when I find a workaround) I’m always torn between letting you know and keeping quiet about it, knowing how busy you are (and how busy I am). When I have the time, I usually do post after agonising about it a bit.