How to generate menu buttons dynamically?

View: New views
4 Messages — Rating Filter:   Alert me  

How to generate menu buttons dynamically?

by hannes.heyder :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

I tried to create a menu button depending on what item was chosen from
another menu button... and now I'm stuck. Therefore it would be really
great if someone could answer my questions:

- How can I get the ID of the menu button that triggered the
(onclick)-event? (I want to make it the parent.)
- Where to find more detailed information about the three parameters
of the fn-callback, defined in the MenuItem?
- Is there a way to hand over some kind of parent-button-depending
container to the button constructor?

I searched through the examples and the documentation several times
and somehow always managed to overlook the necessary information.

Since I am still unexperienced with YUI and JS, I hope that someone
can help me.

Greetings,
Hannes


Re: How to generate menu buttons dynamically?

by wally.ritchie :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

--- In ydn-javascript@..., "hannes.heyder"
<hannes.heyder@...> wrote:

>
> Hello,
>
> I tried to create a menu button depending on what item was chosen from
> another menu button... and now I'm stuck. Therefore it would be really
> great if someone could answer my questions:
>
> - How can I get the ID of the menu button that triggered the
> (onclick)-event? (I want to make it the parent.)
> - Where to find more detailed information about the three parameters
> of the fn-callback, defined in the MenuItem?
> - Is there a way to hand over some kind of parent-button-depending
> container to the button constructor?
>
> I searched through the examples and the documentation several times
> and somehow always managed to overlook the necessary information.
>
> Since I am still unexperienced with YUI and JS, I hope that someone
> can help me.
>
> Greetings,
> Hannes
>
If you are creating the menu button dynamically, you can give it an ID
in the configuration object that you pass as second argument to the
constructor. Otherwise, it generates its own (which you can still find
using the menu object). The menu item has an LI and an A. The text is
in the A but AFAIK either can be triggered.

The parameters to fn-callback are briefly described in the docs for
YAHOO.widget.MenuItem.

You can parent your menu object to whatever container you like. I can
only guess at what you are trying to do, but since you can pass any
object to the on-click handler you can pass the parent menu object. It
might be easier to work with this object which maintains probably
everything you need.

While the yui documentation is very extensive, you can sometimes get a
much more compact and precise picture using FF and Firebug. I seem to
be saying this a lot (I have nothing at all to do with Firebug) but
this tool saves very large amounts of time by allowing you to see
everything. This is especially true if you want to be adding and
deleting menuitems dynamically.


Re: How to generate menu buttons dynamically?

by hannes.heyder :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks for the answer but I still don't get it :(

Perhaps it gets clearer with some code example of mine:

///////////////////////////////////////////////////////////////////

function onIntegerClick(type, args, item) {

  new YAHOO.widget.Button({ type: "menu",
                  label: "Filter", container: "yuiLayoutFilter", menu: xyMenu,
invokingButtonId: ???});
}

var myMenu = [ {text: "1", value: "1", onclick: {fn: onIntegerClick} }];

var attributeButton = new YAHOO.widget.Button({ type: "menu",
          label: "Attribute", container: "yuiLayoutFilter", menu: myMenu});

///////////////////////////////////////////////////////////////////

I want to give the ID of 'attributeButton' to 'onIntegerClick' so that
'invokingButtonId' can be set. The attributeButtons will be created
dynamically.



--- In ydn-javascript@..., "wally.ritchie"
<wally.ritchie@...> wrote:

>
> --- In ydn-javascript@..., "hannes.heyder"
> <hannes.heyder@> wrote:
> >
> > Hello,
> >
> > I tried to create a menu button depending on what item was chosen from
> > another menu button... and now I'm stuck. Therefore it would be really
> > great if someone could answer my questions:
> >
> > - How can I get the ID of the menu button that triggered the
> > (onclick)-event? (I want to make it the parent.)
> > - Where to find more detailed information about the three parameters
> > of the fn-callback, defined in the MenuItem?
> > - Is there a way to hand over some kind of parent-button-depending
> > container to the button constructor?
> >
> > I searched through the examples and the documentation several times
> > and somehow always managed to overlook the necessary information.
> >
> > Since I am still unexperienced with YUI and JS, I hope that someone
> > can help me.
> >
> > Greetings,
> > Hannes
> >
> If you are creating the menu button dynamically, you can give it an ID
> in the configuration object that you pass as second argument to the
> constructor. Otherwise, it generates its own (which you can still find
> using the menu object). The menu item has an LI and an A. The text is
> in the A but AFAIK either can be triggered.
>
> The parameters to fn-callback are briefly described in the docs for
> YAHOO.widget.MenuItem.
>
> You can parent your menu object to whatever container you like. I can
> only guess at what you are trying to do, but since you can pass any
> object to the on-click handler you can pass the parent menu object. It
> might be easier to work with this object which maintains probably
> everything you need.
>
> While the yui documentation is very extensive, you can sometimes get a
> much more compact and precise picture using FF and Firebug. I seem to
> be saying this a lot (I have nothing at all to do with Firebug) but
> this tool saves very large amounts of time by allowing you to see
> everything. This is especially true if you want to be adding and
> deleting menuitems dynamically.
>



Re: How to generate menu buttons dynamically?

by hannes.heyder :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Meanwhile I figured it out. The key was to first create a
'Menu'-object, then the button and then append 'MenuItems' with
buttonIds to the Menu-object.

Greetings,
Hannes

--- In ydn-javascript@..., "wally.ritchie"
<wally.ritchie@...> wrote:

>
> --- In ydn-javascript@..., "hannes.heyder"
> <hannes.heyder@> wrote:
> >
> > Hello,
> >
> > I tried to create a menu button depending on what item was chosen from
> > another menu button... and now I'm stuck. Therefore it would be really
> > great if someone could answer my questions:
> >
> > - How can I get the ID of the menu button that triggered the
> > (onclick)-event? (I want to make it the parent.)
> > - Where to find more detailed information about the three parameters
> > of the fn-callback, defined in the MenuItem?
> > - Is there a way to hand over some kind of parent-button-depending
> > container to the button constructor?
> >
> > I searched through the examples and the documentation several times
> > and somehow always managed to overlook the necessary information.
> >
> > Since I am still unexperienced with YUI and JS, I hope that someone
> > can help me.
> >
> > Greetings,
> > Hannes
> >
> If you are creating the menu button dynamically, you can give it an ID
> in the configuration object that you pass as second argument to the
> constructor. Otherwise, it generates its own (which you can still find
> using the menu object). The menu item has an LI and an A. The text is
> in the A but AFAIK either can be triggered.
>
> The parameters to fn-callback are briefly described in the docs for
> YAHOO.widget.MenuItem.
>
> You can parent your menu object to whatever container you like. I can
> only guess at what you are trying to do, but since you can pass any
> object to the on-click handler you can pass the parent menu object. It
> might be easier to work with this object which maintains probably
> everything you need.
>
> While the yui documentation is very extensive, you can sometimes get a
> much more compact and precise picture using FF and Firebug. I seem to
> be saying this a lot (I have nothing at all to do with Firebug) but
> this tool saves very large amounts of time by allowing you to see
> everything. This is especially true if you want to be adding and
> deleting menuitems dynamically.
>