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

simple_form_for and :namespace #1161

Closed
oprema opened this issue Nov 23, 2014 · 9 comments
Closed

simple_form_for and :namespace #1161

oprema opened this issue Nov 23, 2014 · 9 comments

Comments

@oprema
Copy link

oprema commented Nov 23, 2014

Hi,

I am not sure if this is an issue with simple form.
I have a few objects of the same model I want to edit in one view. To guarantie that the input ids are unique I use the namespace option like that;

= simple_form_for unit, url: users_unit_path(unit), namespace: unit.id, remote: true do |f|
...

Now if I have a association like that:
= f.association :room_properties, label: false, collection: RoomProperty.all, as: :check_boxes

The html that is generated looks like:
...

<div class="control-group check_boxes optional unit_room_properties">
<div class="controls">
<span class="checkbox">
<label name="unit[room_property_ids]" for="unit_room_property_ids_7">
<input id="1_unit_room_property_ids_7" class="check_boxes optional" type="checkbox" value="7" name="unit[room_property_ids][]">
Central heating
</label>

...

As you can see the labels for is "unit_room_property_ids_7" but it should be ""1_unit_room_property_ids_7".
Is it a bug? And if not how do I correct the label to fit with the input id?

Thanks

@rafaelfranca
Copy link
Collaborator

Which version of Simple Form are you using?

@oprema
Copy link
Author

oprema commented Nov 25, 2014

I am on version 3.1.0.rc2.

@rafaelfranca
Copy link
Collaborator

Does it works with the Rails helpers collection_check_box?

@oprema
Copy link
Author

oprema commented Nov 25, 2014

Ok, I changed
= f.association :room_properties, label: false, collection: RoomProperty.all,
to
= f.collection_check_boxes :room_properties, RoomProperty.all, :id, (:)name

Note: Github does not let me use colon-name

it works and the labels are correctly set.

@rafaelfranca
Copy link
Collaborator

Cool, so it is definitely a simple form bug. I'll work on it.
On Nov 25, 2014 4:06 PM, "oprema" notifications@github.com wrote:

Ok, I changed
= f.association :room_properties, label: false, collection:
RoomProperty.all,
to
= f.collection_check_boxes :room_properties, RoomProperty.all, :id, (:)name

Note: Github does not let me use colon-name

it works and the labels are correctly set.


Reply to this email directly or view it on GitHub
#1161 (comment)
.

@oprema
Copy link
Author

oprema commented Nov 25, 2014

Great! Good luck bug hunting.

@oprema
Copy link
Author

oprema commented Nov 28, 2014

Thanks so much. It works ike a charm. Great gem btw.

@rafaelfranca
Copy link
Collaborator

Thanks.

@bhh
Copy link

bhh commented Dec 15, 2014

awesome took me half an hour to to find the namespace feature, getting angry that its broken and finding this thread. and then its already solved, just needed to update ;) so happy that people really care about this little features

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

No branches or pull requests

3 participants