simple popup code

I want to create a very simple popup menu but cannot get it to work.
I have a button on my form (name= ‘pop’) and a method attached to it.
This is my code:

var menu = new Array(
plugins.popupmenu.createMenuItem(‘A’,myMethod),
plugins.popupmenu.createRadioButtonMenuItem(‘B’,myMethod)
)

//passing arguments how?

menu[0].setMethodArguments(menu[0])
menu[1].setMethodArguments(menu[1])

var elem = elements[application.getMethodTriggerElementName()]
if (elem != null)
{plugins.popupmenu.showPopupMenu(elem, menu)}

Can someone point me in the right direction?
TIA,
Ron

You could just use application.showFormInDialog to create your own custom window.

  • David

Thanks for your reply David, but I don’t want to create a
window but do want to use the popup-plugin, as you can see
in my coding.

Regards,
Ron

showPopupMenu expects an element, you provide an element name. So if you change it like this it should work:

var elem = forms[application.getMethodTriggerFormName()].elements[application.getMethodTriggerElementName()]

Sorry Patrick, I know its my ignorance, but still no success.
This is my actual code:

var menu = new Array(
plugins.popupmenu.createMenuItem(‘A’,myMethod),
plugins.popupmenu.createRadioButtonMenuItem(‘B’,myMethod)
)

menu[0].setMethodArguments(menu[0])
menu[1].setMethodArguments(menu[1])

var elem = forms[application.getMethodTriggerFormName()].elements[application.getMethodTriggerElementName()]
if (elem != null)
{plugins.popupmenu.showPopupMenu(elem, menu)}

Your code works for me. Does the element where you want to show the popup have a name (property “name”)?

Where does it fail? Do you get an error? How do your variables look like when you debug through this?

Btw: I don’t understand your assignment of arguments. Why do you want to pass the menu item as argument to the menu item?

Typically, people use the popup like this

var vMenu = new Array();
var vMenuItem;

vMenuItem = plugins.popupmenu.createMenuItem('A',myMethod);
vMenuItem.methodArguments = ['A', 'otherArgument', 1, new Date()] // whatever...
vMenu[vMenu.length] = vMenuItem;
...

var elem = forms[application.getMethodTriggerFormName()].elements[application.getMethodTriggerElementName()]
if (elem != null)
{plugins.popupmenu.showPopupMenu(elem, vMenu )}

Hi Patrick,

The error message says: Reference error: can’t find myMethod.

But lets forget my code, I have no special reason with my coding I am
just trying to popup something, without exacly knowing how things work.
The Servoy sample has to many bells and wishles for me.
So basically I just want a very simple piece of code, with 2 menu-items calling a method, that works, thats all.
From there I want to explore the possibilties myself…
Thanks.

Ron

create a method: myMethod,
it gives an error because that method does not exist yet!

If you just want to popup something and not want any method to be triggered you just pass it a null value like so:

vMenuItem = plugins.popupmenu.createMenuItem('A',null);

Hope this helps.

myMethod does exist Harjo.

Again, I don’t want to continue with my twisted code and
am looking for a very simple piece of code that can trigger a method that works for starters…

Regards,
Ron

Here is some simple code:

// Lets define 2 menuitems that don't trigger any methods
var aMenu = new Array(
	plugins.popupmenu.createMenuItem('Item 1',null),
	plugins.popupmenu.createMenuItem('Item 2',null)
)

// Get the form element name that triggered this method
// Make sure the element does HAVE a name in the name property
var sElementName = elements[application.getMethodTriggerElementName()]
if (sElementName != null) {
	// we have a name, lets show the popup right under this element.
	plugins.popupmenu.showPopupMenu(sElementName, aMenu);
}

Hope this helps.

Yep, this code works!! , even calling a method works fine, thanks Robert.
@Harjo & Patrick: thank you for your suggestions.

Regards,
Ron