question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Discrepancy between .active and :checked in radio button groups when going back to a page via browser history

See original GitHub issue

I have noticed that when I press the “previous” button in my browser, the page is reloaded from cache and the item shown as .active is not the one I clicked last, but the one initially defined as .active in the DOM. This might not match with the actual radio buttons state as the :checked one is the last one clicked. Checkboxes have the same behavior in a similar setup.

I figured a way to overcome this by not using the .active class in the DOM and setting it according to the :checked states of radio buttons at page load.

See this fiddle for an example of the bug, and the temporary fix: https://jsfiddle.net/pr_shadoko/saymu7wa/7/

Tested on : Windows 10 64bit Chrome 63.0.3239.84 / Firefox 57.0 / Opera 49.0 jQuery 3.2.1 BS 4.0.0-beta.3 popper 1.12.9

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
cyclotron3kcommented, May 24, 2018

This is also an issue when selecting something in a radio button group using the keyboard.

1reaction
patrickhlaukecommented, Dec 29, 2017

toggle groups are among some of the most brittle constructs. wondering if there’s a chance to rework them to be pure CSS (maybe styling the label and using a sibling selector, rather than using an .active class on the parent)…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Radio button selection issue when the back button is pressed ...
When the back button is pressed in the browser, I expected both previous answers to still be checked . In Chrome, one previous...
Read more >
RadioButton checked by default no postback browser ... - MSDN
No postback. I realize what's probably happening, the page thinks the radio button hasn't changed so no postback. Disabling the browser's back ......
Read more >
Radio-Controlled Web Design - A List Apart
When a label associated with a radio button is clicked or touched, the radio button is checked while all other radio buttons in...
Read more >
Bootstrap - Quick Guide - Tutorialspoint
Bootstrap is a sleek, intuitive, and powerful, mobile first front-end framework for faster and easier web development. It uses HTML, CSS and Javascript....
Read more >
dropdown typescript react | The AI Search Engine You Control
import React, { useState } from "react"; import Dropdown from ... return ( <button type="button" onClick={handleClick}> Go home </button> ); }.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found