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
Check box collection inputs not checked on collection defined as array of symbols #828
Comments
@hajder what Rails and SimpleForm versions are you using? Just tested it with SimpleForm 3.0.0.rc and Rails 4 and looks like everything works as expected. A sample app that reproduces this issue would be really helpful though. Thanks! |
@nashby Hey, excuse my late resp. simple_form (2.1.0) I will make and link test app tomorrow. |
@hajder tried it with these versions but with no success :( |
I made a test app but can't reproduce this. |
Reproduced the problem (with those same versions mentioned above). Hope this helps anyone |
I can reproduce this issue:
Expected result:
Actual result:
If string is assigned instead, e.g. |
I've debugged So my workaround is: <%= f.input :colours,
:as => :check_boxes,
:collection => [:red, :green, :blue],
:value_method => :to_sym # convert values to symbol
%> |
Just a reminder that whatever is being sent from the form is going to be string, so you're going to receive an array of strings in your controller/model, and you shouldn't be converting them back to symbols because you might be opening a big hole to a symbol DDoS in your application. Thus I'm not sure we should try to make this happen. Thanks! |
I agree with @carlosantoniodasilva. There is no way we can make this reliably work. You need to check the strings are valid values in the model/controller side and convert them to symbols. |
hmm. So the lesson learned is not to use symbols in here? |
Make sense. I'll consider to work on Strings instead of Symbols. Thanks @carlosantoniodasilva :) |
Ok, closing then again. :) |
Thanks everyone 💚💛❤️💙💜 |
serialize :colours, Array |
Hi @thadeu thanks for your comment! Could you please edit it to be in English? |
does anyone have an elegant way disabling inline labels? for example when I'm using the checkbox inside a |
Let's say I have a following model
and a form
so that labels get translated automatically when rendering.
The problem I'm facing is that respective check boxes are not not checked when I am editing an object.
I've found out that a reason for that is Simple Form is not matching symbol named collection elements from field to string values retrieved from database.
Workaround for that is to alter the line like this
but this is, as you may see, quite annoying.
Is it something that you may try to fix? I think value lookup should be performed either on strings or on symbols. Changing behaviour may break some peoples implementations, so I'm not sure what is the best way to fix it.
The text was updated successfully, but these errors were encountered: