Written by

Sales Engineer at InterSystems Corporation
Question Fabio Goncalves · Mar 7, 2016

How to get key value from dropdownmenuitem on Zen Mojo Bootstrap?

I would like to know how to get the key value from a dropdownmenuitem placed on a navbar.

I have tried to get from onselect and onchange events of the template class, but it didn´t  work.

According to the snapshot attached I am trying to retrieve the values from 'action-1' and 'action-2'. 

I have attached a ZIP file with a snapshot which value I am trying to retrieve and example classes.

Thanks.

Comments

Eduard Lebedyuk · Mar 8, 2016

I don't think dropdown menu items support key property. Maybe you can use id property for your purposes instead?

0
Stefan Wittmann · Mar 8, 2016

Dropdownmenuitems did not attach event handlers when a key is present, which is a bug. This is fixed in the next release Zen Mojo 1.1.1. The new version is currently verified by QD, so you can expect a release within the next 2 weeks.

0
Fabio Goncalves · Mar 8, 2016

OK. I am going to wait for the next release.

Thanks.

0
Jochen Roese · Mar 9, 2016

As temp  solution you can use href:"javascript:zenPage.StartEvent('yourkey','onclick','yourvalue');"

In your Zenpage add following ClientMethod to call events (sometimes useful for handling zen-events with bootstrap-plugins):

ClientMethod StartEvent(
key,
eventType,
value) [ Language = javascript ]
{
var newArea "events-" key.split(":")[0];
if (zenPage.currArea!==newArea) {
zenPage.currArea newArea;
zenPage.loadTemplateNS(zenPage.templateDispatchBaseNamespace+"/events",key.split(":")[0],newArea);
}
var st zenPage.getTemplate();
st[eventType](key,value,'mainView');
}

0
Stefan Wittmann · Mar 9, 2016

Jochen, this code will only work if the template dispatch mode is enabled. If you are running in standard mode, this is the code you need to make the sample work:

ClientMethod StartEvent(
key,
eventType,
value) [ Language = javascript ]
{
var st = zenPage.getTemplate();
st.[eventType](key,value,'mainView');
}
0
Jochen Roese · Mar 10, 2016

That should do it for both types:

ClientMethod StartEvent(
key,
eventType,
value) [ Language = javascript ]
{
if (zenPage.templateDispatchMode) {
var newArea "events-" key.split(":")[0];
if (zenPage.currArea!==newArea) {
zenPage.currArea newArea;
zenPage.loadTemplateNS(zenPage.templateDispatchBaseNamespace+"/events",key.split(":")[0],newArea);
}
}
var st zenPage.getTemplate();
st[eventType](key,value,'mainView');
}
0
Stefan Wittmann  Mar 10, 2016 to Jochen Roese

This looks much better and should work.

Thanks for providing a workaround.

Stefan

0