-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Comments
Thank you for reporting, but could you provide an example application please. We have tests that ensure this behavior. |
I created a simple rails application with just a model and this form and the gem works perfectly. |
A lot of thing changed since SimpleForm 1.5. Almost all the implementation of 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. |
One thing that you can do to help us to debug it is posting the generated HTML for the |
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 |
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. |
Yeah. You are right. Fixing now. Thanks mate ❤️ |
Fixed. I'll release a new version later. |
Could you test the master branch and see if the bug was fixed? |
Yes, it is working now! Thanks! |
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.
The text was updated successfully, but these errors were encountered: