Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<input type="radio"> checked state not saved #84

Closed
zerodogg opened this issue Jan 1, 2018 · 3 comments
Closed

<input type="radio"> checked state not saved #84

zerodogg opened this issue Jan 1, 2018 · 3 comments
Labels

Comments

@zerodogg
Copy link

zerodogg commented Jan 1, 2018

The state of radio input elements is not saved ot the generated html. React doesn't update it on hydrate() so for pages where there's a default checked radio button the form stays empty until the user clicks something. If there are multiple sets of radio buttons, when the user clicks one, react will also update the state of the other ones, so clicking any radio button suddenly displays the default values of the other radio buttons as well.

I'm using reactstrap, its input elements are using the checked property, which doesn't get written to the dom as attributes, but for the prerendered page it needs to be written out.

@stereobooster
Copy link
Owner

stereobooster commented Jan 1, 2018

Solution would be the same as #79. Walk through all radios and write out checked dom property as html attribute.

Array.from(document.querySelectorAll('[type=radio]'))
  .forEach(x => { 
    if (x.checked) { 
      x.setAttribute('checked', 'checked')
    }
  });

I wonder what else should be fixed that way

stereobooster added a commit that referenced this issue Jan 1, 2018
stereobooster added a commit that referenced this issue Jan 1, 2018
@stereobooster
Copy link
Owner

fixed in 1.7.0

@zerodogg
Copy link
Author

zerodogg commented Jan 1, 2018

Fantastic, thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants