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

When using collection_radio_buttons or collection_check_boxes the persisted state does not show #474

Closed
glampr opened this issue Feb 26, 2012 · 10 comments
Assignees
Labels

Comments

@glampr
Copy link

glampr commented Feb 26, 2012

In an update form when using a collection_radio_buttons or collection_check_boxes the generated output does not show the persisted state of the attribute. This happens for db and non-db attributes. When the form is rendered the option(s) with the previously selected and saved value(s) is/are not checked.

@rafaelfranca
Copy link
Collaborator

Thank you for reporting, but could you provide an example application please. We have tests that ensure this behavior.

@glampr
Copy link
Author

glampr commented Feb 26, 2012

I created a simple rails application with just a model and this form and the gem works perfectly.
However in my normal big application, the issue remains. This occurred with the upgrade to 2.0.0.
When I switch simple_form back to 1.5.1 the form works correctly. I have commented out the configuration file.
Any thoughts on how to debug this? Could it be conflicting with something else? What changed in 2.0.0 (besides the name of collection_radio -> collection_radio_buttons)?

@rafaelfranca
Copy link
Collaborator

A lot of thing changed since SimpleForm 1.5. Almost all the implementation of collection_radio_buttons and collection_check_boxes changed. This issue is really weird.

Could you try to debug your application and see where it was changing. You can use bundle open to open SimpleForm code and put one debugger line inside these methods.

@rafaelfranca
Copy link
Collaborator

One thing that you can do to help us to debug it is posting the generated HTML for the collection_check_boxes and collection_radio_buttons and also the output for <%= f.object.attribute_used_with_collection_* %>

@glampr
Copy link
Author

glampr commented Feb 26, 2012

This is the output of collection_radio for 2.0.0

<div><input id="profile_subskill_unique_id_1" name="profile[subskill_unique_id]" type="radio" value="1" />
<label class="collection_radio_buttons" for="profile_subskill_unique_id_1">Lead role</label></div>
<div><input id="profile_subskill_unique_id_2" name="profile[subskill_unique_id]" type="radio" value="2" />
<label class="collection_radio_buttons" for="profile_subskill_unique_id_2">Known</label></div>
<div><input id="profile_subskill_unique_id_3" name="profile[subskill_unique_id]" type="radio" value="3" />
<label class="collection_radio_buttons" for="profile_subskill_unique_id_3">Upcoming</label></div>
<div><input id="profile_subskill_unique_id_4" name="profile[subskill_unique_id]" type="radio" value="4" />
<label class="collection_radio_buttons" for="profile_subskill_unique_id_4">Drama school student</label></div>
<div><input id="profile_subskill_unique_id_5" name="profile[subskill_unique_id]" type="radio" value="5" />
<label class="collection_radio_buttons" for="profile_subskill_unique_id_5">Amateur</label></div>
<div><input id="profile_subskill_unique_id_129" name="profile[subskill_unique_id]" type="radio" value="129" />
<label class="collection_radio_buttons" for="profile_subskill_unique_id_129">New</label></div>
<div><input id="profile_subskill_unique_id_183" name="profile[subskill_unique_id]" type="radio" value="183" />
<label class="collection_radio_buttons" for="profile_subskill_unique_id_183">Acknowledged</label></div>
<div><input id="profile_subskill_unique_id_238" name="profile[subskill_unique_id]" type="radio" value="238" />
<label class="collection_radio_buttons" for="profile_subskill_unique_id_238">Experienced</label></div>

and this is the output of collection_radio for 1.5.1

<div><input id="profile_subskill_unique_id_1" name="profile[subskill_unique_id]" type="radio" value="1" />
<label class="collection_radio" for="profile_subskill_unique_id_1">Lead role</label></div>
<div><input id="profile_subskill_unique_id_2" name="profile[subskill_unique_id]" type="radio" value="2" />
<label class="collection_radio" for="profile_subskill_unique_id_2">Known</label></div>
<div><input checked="checked" id="profile_subskill_unique_id_3" name="profile[subskill_unique_id]" type="radio" value="3" />
<label class="collection_radio" for="profile_subskill_unique_id_3">Upcoming</label></div>
<div><input id="profile_subskill_unique_id_4" name="profile[subskill_unique_id]" type="radio" value="4" />
<label class="collection_radio" for="profile_subskill_unique_id_4">Drama school student</label></div>
<div><input id="profile_subskill_unique_id_5" name="profile[subskill_unique_id]" type="radio" value="5" />
<label class="collection_radio" for="profile_subskill_unique_id_5">Amateur</label></div>
<div><input id="profile_subskill_unique_id_129" name="profile[subskill_unique_id]" type="radio" value="129" />
<label class="collection_radio" for="profile_subskill_unique_id_129">New</label></div>
<div><input id="profile_subskill_unique_id_183" name="profile[subskill_unique_id]" type="radio" value="183" />
<label class="collection_radio" for="profile_subskill_unique_id_183">Acknowledged</label></div>
<div><input id="profile_subskill_unique_id_238" name="profile[subskill_unique_id]" type="radio" value="238" />
<label class="collection_radio" for="profile_subskill_unique_id_238">Experienced</label></div>

and of course p.object.subskill_unique_id.inspect outputs 3.

@glampr
Copy link
Author

glampr commented Feb 26, 2012

Ok, the problem seems to be that I am rendering a form with a local and NOT an instance variable. Will investigate further why this is happening, since when I use the built-in rails helper the radio button get properly selected or not.

UPDATE:

Seems that you switched to using the @template.radio_button(object_name, method_name, method_value, options) instead of the @form_builder(method_name, method_value, options) and the first one does not work if there is no instance variable with object_name.

@rafaelfranca
Copy link
Collaborator

Yeah. You are right. Fixing now. Thanks mate ❤️

@rafaelfranca
Copy link
Collaborator

Fixed. I'll release a new version later.

@rafaelfranca
Copy link
Collaborator

Could you test the master branch and see if the bug was fixed?

@glampr
Copy link
Author

glampr commented Feb 26, 2012

Yes, it is working now! Thanks!

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

No branches or pull requests

2 participants