carmen-ruby / carmen-rails

NOT ACTIVELY MAINTAINED Rails adapter for Carmen (provides country_select and subregion_select)
MIT License
215 stars 159 forks source link

Modified country_select to permit passing :object as an option. #19

Closed tinynumbers closed 11 years ago

tinynumbers commented 11 years ago

I'm faced with the following scenario:

The Address object was not being passed through the whole field generation stack so therefore the previously-set value for the Address country was not being pre-selected in the country_select.

To fix this, I've added the ability for country_select to pull the object from the args in the same way that subregion_select does. That way I can pass the object manually from my sub-form, e.g.:

= subform.input :country_code, :as => :country, 
                :priority_countries => %w[US CA], 
                :object => subform.object
epchris commented 11 years ago

+1 for this fix, implemented it in our fork too to address the same problem.

ghost commented 11 years ago

Looks good. I'd like to see this in as well, so I will test and merge this soon - as I love Formtastic. :+1:

kevinwmerritt commented 11 years ago

I am experiencing a similar problem using carmen-rails with simple_form. The object support in this pull solves it.

Here is the code that ensures the persisted country is selected when the form is rendered:

<%= f.input :country_code, label: 'Country' do %>
    <%= f.country_select :country_code, {object: f.object, prompt: 'Select a country'} %>
<% end %>

@CDainMiller when this is merged in, I will update the readme with a simple_form example.

ghost commented 11 years ago

Love it. Tested via simple_form & formtastic, seems fine to me. Also thanks Kevin for the validation, and for offering to update the README.