Understanding Popup Menu

My intention is to have this running from a “New” button on my activities form.

When I select it, it runs “myMethod” three times and pops up the menu. I thought it would only run the method after selection of a menutype. What have I done wrong?
Also I don’t understand what menu[2].setMe… line does. Can someone explain?

Thank you.

var menu = new Array(//if you assign this array to a global its reusable
	plugins.popupmenu.createMenuItem('Task',myMethod),
	plugins.popupmenu.createMenuItem(''RFI',myMethod),
	plugins.popupmenu.createMenuItem('Note',mylMethod)
)


// To transfer the right element and formname triggers you have to set them as arguments
menu[2].setMethodArguments(new Array(application.getMethodTriggerElementName(), application.getMethodTriggerFormName()));

var elem = elements[application.getMethodTriggerElementName()]
if (elem != null)
{
	plugins.popupmenu.showPopupMenu(elem, menu);
//or you can set the coordinates : plugins.popupmenu.showPopupMenu(10, 10, menu);
}

James,

I think you are mixing the method that creates the menu and the method that is called on click of a menu-item.

The code you are showing is typically called from an on-action of a button or a right-click method.

The myMethod method is the code that should be executed when the user selects an item from the menu.

menu[2].setMethodArguments(…) sets the callback arguments for the third menuitem in the menu array.

Rob

It is connected to the onAction event for a button. When I select this button myMethod runs “5” times (at the moment myMethod pops a warning dialog) and then shows the popup menu. When I then select an option on the popup menu nothing happens.

function btn_popup() {
	
var menu = new Array(//if you assign this array to a global its reusable
	plugins.popupmenu.createMenuItem('Task',myMethod),
	plugins.popupmenu.createMenuItem('Note',myMethod),
	plugins.popupmenu.createMenuItem('Email',myMethod),
	plugins.popupmenu.createMenuItem('RFI', myMethod),
	plugins.popupmenu.createMenuItem('Letter', myMethod)
)

// To trnsfer the right element and formname triggers you have to set them as arguments
menu[2].setMethodArguments(new Array(application.getMethodTriggerElementName(), application.getMethodTriggerFormName()));

var elem = elements[application.getMethodTriggerElementName()]
if (elem != null)
{
	plugins.popupmenu.showPopupMenu(elem, menu);
//or you can set the coordinates : plugins.popupmenu.showPopupMenu(10, 10, menu);
}

}

Ok, I was curious about this one so I grabbed your code and tried it out for myself, just substituting “myMethod” with one of my own. I don’t know why your method is running 5 times because it isn’t doing that for me. Since it is working fine for me, I don’t think it is because of the menu triggering accidentally. My best guess is that you have this method attached to some other events. So I would check that out. Also, as Rob mentioned with the arguments, you are passing argument s for the Trigger Element and Trigger Form Name to myMethod when you click Email but on no others. If you wanted arguments passed for each one you would need to do something like the following. Again, your code seems to be working fine for me.

menu[0] = “taskargument”
menu[1] = “noteargument”
menu[2] = “emailargument”
menu[3] = “rfiargument”

Thanks Matt. I will create a blank solution and try again. probably something I should have done in the first place.

Funny thing. I only decided to look at popup menu after watching the adBlocks product video a couple of days ago.

Cya.

Hmmmmm.

Created new solution and tried again with the same result. Refer attached solution.

Thank you.

test1.servoy (3.58 KB)

Perfect. That solution showed me the problem that wasn’t apparent in the post. When you build your menu you are actually calling the method instead of just creating a reference to it.

Currently when you create a menu item you do this:
plugins.popupmenu.createMenuItem(‘Letter’,globals.clicked())

It should look be this:
plugins.popupmenu.createMenuItem(‘Letter’,globals.clicked)

Notice that the only change is that I removed the parentheses after globals.clicked. Writing globals.clicked is a reference to the method so it can be called later, writing globals.clicked() will actually call it.

Did I mention I love Brisbane and if you want to ship me out there for a week or two my bags are nearly packed?

Matt,

Sorry, no room left. The secret is out and we can’t stop em all from coming over!

Final question regarding the formatting, refer attached, Each menu option has a left margin (Why) and does html rendering always look so icky?

J

4xjbh:
Matt,

Sorry, no room left. The secret is out and we can’t stop em all from coming over!

Final question regarding the formatting, refer attached, Each menu option has a left margin (Why) and does html rendering always look so icky?

J

I had the same issue with the left margin and found that it was being caused by the Java LAF I was using. If you change the Look and Feel of the client to a different LAF you will probably see this go away.

Keith