Event handler for radiobutton menu items?

Talk about code development, features, specific bugzilla bugs, enhancements, patches, and other highly technical things.
Forum rules
Please keep everything here strictly on-topic.
This board is meant for Pale Moon source code development related subjects only like code snippets, patches, specific referenced Bugzilla bugs, mercurial, etc.

This is not for tech support! Please do not post tech support questions in the "Development" board!
Please make sure not to use this board for support questions. Most "bug reports" do not belong in this board and should initially be posted in Community Support or other relevant support boards.

Please keep things on-topic as this forum will be used for reference for Pale Moon development. Expect topics that aren't relevant as such to be moved or deleted.
Post Reply
User avatar
moonbat
Board Warrior
Board Warrior
Posts: 1605
Joined: 2015-12-09, 15:45

Event handler for radiobutton menu items?

Post by moonbat » 2020-04-22, 14:02

I'm making a cascading popup menu with 3 items - a checkbox and 2 radiobuttons, and the checkbox also toggles whether the radio buttons are disabled (i.e. if the checkbox is unchecked, the radio buttons are disabled).
Per the MDN documentation, you group the radio menuitems by giving them a common name, and not by using a radiobuttongroup as is the case for regular radiobuttons. How do I capture events or detect which one is selected? The page also says that you can place the oncommand in the enclosing menupopup - but that makes sense only if all the items in the submenu are radio buttons, and that isn't the case here.

The command element doesn't have anything to query radiobuttons.

I've tried attaching the oncommand handler to the menupopup, and commonly to all 3 menu items but it doesn't respond to events. Is there an easier way to do this?
"One hosts to look them up, one DNS to find them and in the darkness BIND them."

Linux Mint 20 Xfce x64 on HP i5 laptop with 12 GB RAM, always latest versions of PM & Basilisk unless specified.

thosrtanner
Lunatic
Lunatic
Posts: 290
Joined: 2014-05-10, 18:19
Location: UK

Re: Event handler for radiobutton menu items?

Post by thosrtanner » 2020-04-22, 18:35

Personal opinion only: I think radio buttons in a menu would be confusing to use.

User avatar
Isengrim
Board Warrior
Board Warrior
Posts: 1166
Joined: 2015-09-08, 22:54
Location: 127.0.0.1
Contact:

Re: Event handler for radiobutton menu items?

Post by Isengrim » 2020-04-22, 23:24

You can add an "oncommand" attribute to each menu item to handle selection of that item, just as the MDN documentation shows.

Code: Select all

<menuitem id="my-menuitem" label="&label;" type="radio" oncommand="Command(args);" />
If you wanted to, you could use the same method for all of your radio items and either have each item pass a different parameter, or within that command check each item and determine which is selected.

On a side note, if the checkbox disables the other two radio items, wouldn't that just work the same as three radio items? :P
Linux Mint 19.3 Cinnamon (64-bit), Debian Bullseye (64-bit), Windows 7 (64-bit), Windows 10 build 1803 (64-bit)
"As long as there is someone who will appreciate the work involved in the creation, the effort is time well spent." ~ Tetsuzou Kamadani, Cave Story

User avatar
moonbat
Board Warrior
Board Warrior
Posts: 1605
Joined: 2015-12-09, 15:45

Re: Event handler for radiobutton menu items?

Post by moonbat » 2020-04-23, 02:43

Isengrim wrote:
2020-04-22, 23:24
On a side note, if the checkbox disables the other two radio items, wouldn't that just work the same as three radio items? :P
D'oh! :oops:
"One hosts to look them up, one DNS to find them and in the darkness BIND them."

Linux Mint 20 Xfce x64 on HP i5 laptop with 12 GB RAM, always latest versions of PM & Basilisk unless specified.

Post Reply