checkbox popup menu

I’m trying create a method that shows a valuelist with checkboxes next to each value when button is clicked.
So far this is what I have

var engDataSet = application.getValueListItems(‘engineerlist’)
var engNames = engDataSet.getColumnAsArray(1) //get the name of all the engineers
var submenu = new Array()

for(var i = 1; i < engDataSet.getMaxRowIndex(); i ++)
{
submenu[i-1] = plugins.popupmenu.createCheckboxMenuItem(engNames*, myMethod())*

  • submenu[i-1].setMethodArguments(new Array(application.getMethodTriggerElementName(),application.getMethodTriggerFormName()))*
    }
    var menu = new Array (plugins.popupmenu.createMenuItem(‘Engineers’, submenu))
    menu[0].setSelected(true);
    var elem = elements[application.getMethodTriggerElementName()];
    if (elem != null)
    {
  • plugins.popupmenu.showPopupMenu(elem, menu);*
    } [/quote]
    I’m very unsure what should be in myMethod().

myMethod is the method that will be fired if the user selects a menu item. But you pass that in the wrong way, an error that many people seem to make.

If you want to pass a method to a plugin, you have to pass it as

myMethod

simply that. A typical error is

myMethod()

which will execute that method right where you have put that and pass a possible result of myMethod to the plugin instead of a reference to that method. Also wrong is

'myMethod'

which will simply pass a String.

thanks,

it’s working now. but now I have 2 more questions.

  1. is it possible for the users to check/select a few values on the checkbox popup menu before the menu closes. So far, the menu closes after a value is selected.
  2. I want “myMethod” to get the text of the value that has been selected. How does “myMethod” know which value is selected???
  1. I don’t think so. It’s just the way popup menus work.
  2. You can pass any argument to any menu entry. For example in your case
for(var i = 1; i < engDataSet.getMaxRowIndex(); i ++)
{
submenu[i-1] = plugins.popupmenu.createCheckboxMenuItem(engNames[i], myMethod())

submenu[i-1].setMethodArguments(new Array(application.getMethodTriggerElementName(),application.getMethodTriggerFormName(), engNames[i]))
}

So the third argument is the name of the engineer of a particular menu entry. Your myMethod could then do

var vEngineerName = arguments[2] // array is 0 based!

Hope this helps.

Thanks,

your suggestion to the 2nd question makes lots of sense.

ps: its too bad that the popup menu wont allow for multiple selections