Event handler for radiobutton menu items?

Talk about code development, features, specific bugs, enhancements, patches, and similar 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 bugs, git, the repositories, 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. Please post issues with specific websites, extensions, etc. in the relevant boards for those topics.

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.
User avatar
moonbat
Knows the dark side
Knows the dark side
Posts: 4971
Joined: 2015-12-09, 15:45
Contact:

Event handler for radiobutton menu items?

Unread 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."

Image
Linux Mint 21 Xfce x64 on HP i5-5200 laptop, 12 GB RAM.
AutoPageColor|PermissionsPlus|PMPlayer|Pure URL|RecordRewind|TextFX

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

Re: Event handler for radiobutton menu items?

Unread 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: 1325
Joined: 2015-09-08, 22:54
Location: 127.0.0.1
Contact:

Re: Event handler for radiobutton menu items?

Unread 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
a.k.a. Ascrod
Linux Mint 19.3 Cinnamon (64-bit), Debian Bullseye (64-bit), Windows 7 (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
Knows the dark side
Knows the dark side
Posts: 4971
Joined: 2015-12-09, 15:45
Contact:

Re: Event handler for radiobutton menu items?

Unread 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."

Image
Linux Mint 21 Xfce x64 on HP i5-5200 laptop, 12 GB RAM.
AutoPageColor|PermissionsPlus|PMPlayer|Pure URL|RecordRewind|TextFX

Locked