Collection not selecting value #325

Closed
cyrilpic opened this Issue Sep 15, 2011 · 6 comments

Projects

None yet

2 participants

@cyrilpic

If I provide a lambda function to the label_method options, the select input doesn't select any options.

f.input :status, :collection => Project.possible_status, :label_method => lambda { |v| I18n.t v.to_s }

Even if the status attribute of the model is set to a particular value, the html code produced doesn't set the selected option on any options under the select tag.

@carlosantoniodasilva

Which SimpleForm version are you using? We've improved some stuff related to label/value methods and disabled with selects when they're given as procs, perhaps that might be the issue. Thanks.

@cyrilpic

I'm using SimpleForm 1.5.0. I saw the changes you made to correct issue #307, but it seemed to cause me some troubles.

I can make it work again, by adding :

:selected => lambda { |v| v == f.object.status }

I must probably add that my field is actually a Symbol.

@carlosantoniodasilva

I think I can see what's happening, we might be overriding the :selected option, which makes Rails ignore the current attribute value.. I'll try a fix in the following days.

Thanks for reporting.

@carlosantoniodasilva

Hey mate, I believe the issue was exactly what I had in mind. Could you please try to bundle from github, branch v1.5, and test it? If everything goes fine we will release a new version. Thanks.

@cyrilpic

Works perfectly now ! Thanks for the quick fix

@carlosantoniodasilva
@klobuczek klobuczek pushed a commit to klobuczek/simple_form that referenced this issue Oct 4, 2011
@carlosantoniodasilva carlosantoniodasilva Do not override attribute value selection in collection select. Closes
…#325

Conflicts:

	test/inputs_test.rb
42307c1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment