Skip to content

Instantly share code, notes, and snippets.

@kapowaz
Created May 28, 2014 14:14
Show Gist options
  • Save kapowaz/81c9e3153f799e6e13c6 to your computer and use it in GitHub Desktop.
Save kapowaz/81c9e3153f799e6e13c6 to your computer and use it in GitHub Desktop.
This monstrosity comes from Spree's address form view.
<% if Spree::Config[:address_requires_state] %>
<p class="field" id=<%="#{address_id}state" %>>
<% have_states = !address.country.states.empty? %>
<%= form.label :state, Spree.t(:state) %><span class='required' id=<%="#{address_id}state-required"%>>*</span><br/>
<% state_elements = [
form.collection_select(:state_id, address.country.states,
:id, :name,
{:include_blank => true},
{:class => have_states ? 'required' : 'hidden',
:disabled => !have_states}) +
form.text_field(:state_name,
:class => !have_states ? 'required' : 'hidden',
:disabled => have_states)
].join.gsub('"', "'").gsub("\n", "")
%>
<%= javascript_tag do -%>
$('#<%="#{address_id}state" %>').append("<%== state_elements %>");
<% end %>
</p>
<noscript>
<%= form.text_field :state_name, :class => 'required' %>
</noscript>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment