DEV Community

Joe Steinbring
Joe Steinbring

Posted on

1

How to make the radio control unclickable

I found myself sitting at the laptop at 10:00 on a Sunday night, thinking about a request that the boss had for one of my apps. This past week, he asked "What if you accidentally click on a radio control, you want to deselect what you clicked, and you don't want to refresh the webpage? What do you do, then?" After two "Dunkin' Pumpkin" beers, I figured that it would be an interesting challenge to think about.

With some onClick magic and a variable to hold the value prior to the click event, it is just a matter of writing an if/else statement for each of the radio controls.

In the above example, the first set is a demonstration of the default behavior. The second set is with the new, modified behavior.

So, what do you think? Let me know in the comments if you have an easier method.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs