How to display checked value for radio button collection

Wasabi Developer

Question about Rails 5 and collection_radio_buttons.

How do you have it display the checked value of a radio input when you try and edit the form?

<%= collection_radio_buttons(:post, :category_id, Category.all, :id, :name) do |b| %>
  <div class="radio">
     <%= b.label do %>
       <%= b.radio_button + b.text %>
     <% end %>
  </div>
<% end %>

With select box f.collection_select it remembers the value but not with collection_radio_buttons

My routes file is as follows

Routes

resources :posts, as: :entries

Wasabi Developer

I've figured it out.

It's because I'm using the collection_radio_buttons directly instead of using the form helper object.

From (not storing user value)

<%= collection_radio_buttons(:post, :category_id, Category.all, :id, :name) do |b| %>
  <div class="radio">
     <%= b.label do %>
       <%= b.radio_button + b.text %>
     <% end %>
  </div>
<% end %>

To (now saving user values)

# Using the form helper `f.collection_radio_buttons` 
# instead of `collection_radio_buttons`. 
# Also removed passing the object in as an argument

<%= f.collection_radio_buttons(:category_id, Category.all, :id, :name) do |b| %>
  <div class="radio">
     <%= b.label do %>
       <%= b.radio_button + b.text %>
     <% end %>
  </div>
<% end %>

I hope this helps anyone in the future.

Thanks

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to display the checked radio button value in angularJs

From Dev

How to display checked radio button based on previous value?

From Dev

how to get checked radio button value in javascript

From Dev

Display radio button checked if json value is match to condition

From Dev

if radio button checked display div

From Dev

How to get the value of the checked radio button and the remaining td's but not include the radio button that has not been checked (in tr)

From Dev

If radio button checked submit value?

From Dev

How to reset Spinner value to "Select by something" based on Radio Button checked

From Dev

How to retrieve radio button value from database in checked state in jsp

From Dev

How to send the checked radio button value to Server in angular js

From Dev

How can i keep the radio button checked and get the value

From Dev

How to set checked="checked" in first radio button?

From Dev

Image Radio Button Checked Display Issues

From Dev

if radio button is checked, display divs and textbox

From Dev

Javascript: How to get the value from a checked radio button when more than one radio button is present

From Dev

Ruby on rails - How to display different radio buttons once another radio button is checked?

From Dev

How to get value of checked radio?

From Dev

Android - How to enable a button if a radio button is checked?

From Dev

Getting value of checked radio button by name of radio button?

From Dev

Using the radio button 'checked' value in HTML and PHP

From Dev

javascript radio button return previous checked value

From Dev

Toggling a disabled radio button and changing checked value

From Dev

Can't get value of checked radio button

From Dev

how to set checked radio button by checking another radio button

From Dev

How can I get the text of radio button if radio button checked?

From Dev

How to render checked radio button in React

From Dev

How to set a certain radio button to checked "true"

From Dev

How to add checked class to a radio button in AngularJS

From Dev

how to find checked radio button in a gridview?

Related Related

  1. 1

    How to display the checked radio button value in angularJs

  2. 2

    How to display checked radio button based on previous value?

  3. 3

    how to get checked radio button value in javascript

  4. 4

    Display radio button checked if json value is match to condition

  5. 5

    if radio button checked display div

  6. 6

    How to get the value of the checked radio button and the remaining td's but not include the radio button that has not been checked (in tr)

  7. 7

    If radio button checked submit value?

  8. 8

    How to reset Spinner value to "Select by something" based on Radio Button checked

  9. 9

    How to retrieve radio button value from database in checked state in jsp

  10. 10

    How to send the checked radio button value to Server in angular js

  11. 11

    How can i keep the radio button checked and get the value

  12. 12

    How to set checked="checked" in first radio button?

  13. 13

    Image Radio Button Checked Display Issues

  14. 14

    if radio button is checked, display divs and textbox

  15. 15

    Javascript: How to get the value from a checked radio button when more than one radio button is present

  16. 16

    Ruby on rails - How to display different radio buttons once another radio button is checked?

  17. 17

    How to get value of checked radio?

  18. 18

    Android - How to enable a button if a radio button is checked?

  19. 19

    Getting value of checked radio button by name of radio button?

  20. 20

    Using the radio button 'checked' value in HTML and PHP

  21. 21

    javascript radio button return previous checked value

  22. 22

    Toggling a disabled radio button and changing checked value

  23. 23

    Can't get value of checked radio button

  24. 24

    how to set checked radio button by checking another radio button

  25. 25

    How can I get the text of radio button if radio button checked?

  26. 26

    How to render checked radio button in React

  27. 27

    How to set a certain radio button to checked "true"

  28. 28

    How to add checked class to a radio button in AngularJS

  29. 29

    how to find checked radio button in a gridview?

HotTag

Archive