Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
New Developer
svzi
Posts: 51
Registered: ‎04-04-2012
My Device: Z30, Z10LE, Q5 & PlayBook
My Carrier: German Provider
Accepted Solution

Trouble with custom context menu on BB10

Hi all,

 

I'm currently trying to implement a custom context menu with my webworks application. So far I'm not creating a normal webworks / bbUI app, but I'm trying to add some main functionalities from bbUI. So to speak I have some different elements in my app, each of them triggers the context menu as expected. So far, so good. But now I have some trouble to detect which element / div triggered the context menu call. How can I get that information?

 

I'm adding the context menu like this:

 

var contexts = [blackberry.ui.contextmenu.CONTEXT_ALL];
var itemRead = {
    actionId: 'actionRead', 
    label: 'Read Article', 
    icon:'../assets/images/new/add.png'
};
  	    
blackberry.ui.contextmenu.addItem(contexts, itemShare, function(arg1) { 
    console.log("itemShare: " + arg1);
});     

 But as I already described arg1 is null, and I have no clue on how to detect the caller.

 

Can somebody help me, please?

 

Thank you very much in advance!

 

Cheers,

Sven

---
Developer ReadItNow!, PhotoUpload, WhereIs...?, Magic4Square and OrganizeMe!

http://sven-ziegler.com
Please use plain text.
New Developer
svzi
Posts: 51
Registered: ‎04-04-2012
My Device: Z30, Z10LE, Q5 & PlayBook
My Carrier: German Provider

Re: Trouble with custom context menu on BB10

For example my screen contains some DIVs:

 

<div id="stuff">
	<div id="A">1</div>
	<div id="B">2</div>
	<div id="C">3</div>
</div>

 When I tap and hold number 2 the context menu (see my first post) appears. When I select something from that context menu, I want to know which DIV (A, B or C) where selected with tap & hold. 


Sadly this piece of code: 

blackberry.ui.contextmenu.addItem(contexts, itemShare, function(arg1) { 
    console.log("itemShare: " + arg1);
});     

Does not show that information. How can I detect that it was the div with the id "B"?

 

Cheers,

Sven

---
Developer ReadItNow!, PhotoUpload, WhereIs...?, Magic4Square and OrganizeMe!

http://sven-ziegler.com
Please use plain text.
BlackBerry Development Advisor (Retired)
erikjohnzon
Posts: 245
Registered: ‎09-21-2012
My Device: Q10
My Carrier: Virgin

Re: Trouble with custom context menu on BB10

You need the feature called custom context. This will provide you the information on what DIV has been pressed. When you define your DIV, add a tag called: data-webworks-context

 

So your div would look something like this:

 

<div id="stuff">
	<div id="A" data-webworks-context="{ "id": "1", "type" : "definedContext", "header": "A custom header", "subheader": "your custom subheader" }" >1</div>
	<div id="B" data-webworks-context="{ "id": "2", "type" : "definedContext", "header": "A custom header", "subheader": "your custom subheader" }" >2</div>
	<div id="C" data-webworks-context="{ "id": "3", "type" : "definedContext", "header": "A custom header", "subheader": "your custom subheader" }" >3</div>
</div>
blackberry.ui.contextmenu.addItem(contexts, itemShare, function(id) { 
    console.log("itemShare: " + id); 
});

You are passing a JSON object to the CCM, and asking it to return to you the ID of the element that invoked the context menu, so you can do some work. Let me know if that helps :smileyhappy:

@erikjohnzon
erjohnson@blackberry.com
Please use plain text.
New Developer
svzi
Posts: 51
Registered: ‎04-04-2012
My Device: Z30, Z10LE, Q5 & PlayBook
My Carrier: German Provider

Re: Trouble with custom context menu on BB10

[ Edited ]

Awesome, that works!

 

Thank you very much! :-)

 

Best,

Sven

---
Developer ReadItNow!, PhotoUpload, WhereIs...?, Magic4Square and OrganizeMe!

http://sven-ziegler.com
Please use plain text.
BlackBerry Development Advisor (Retired)
erikjohnzon
Posts: 245
Registered: ‎09-21-2012
My Device: Q10
My Carrier: Virgin

Re: Trouble with custom context menu on BB10

No, as long as the parser can recognize it as a string. I would swap out the " for a single quote ' on the start and end ie: data-webworks-context='{ "id: "1"......}'.

 

Did it work?

@erikjohnzon
erjohnson@blackberry.com
Please use plain text.
New Developer
svzi
Posts: 51
Registered: ‎04-04-2012
My Device: Z30, Z10LE, Q5 & PlayBook
My Carrier: German Provider

Re: Trouble with custom context menu on BB10

I thought about it by myself and came to the same conclusion. 

 

You really helped me a lot, thank you very much!

 

Best,

Sven

---
Developer ReadItNow!, PhotoUpload, WhereIs...?, Magic4Square and OrganizeMe!

http://sven-ziegler.com
Please use plain text.
BlackBerry Development Advisor (Retired)
erikjohnzon
Posts: 245
Registered: ‎09-21-2012
My Device: Q10
My Carrier: Virgin

Re: Trouble with custom context menu on BB10

Awesome, glad it worked. I have a stale blog post on the topic I really need to get out there for more information.

@erikjohnzon
erjohnson@blackberry.com
Please use plain text.