I am working on a project that is built on spree and am trying to concatenate state abbreviations to the state's name in the dropdown when selecting shipping address.
Example: "New York - NY" instead of "New York"
The shipping address form can be found here with the code making the state selection dropdown below:
<% if Spree::Config[:address_requires_state] %>
<p class="form-group" id=<%="#{address_id}state" %>>
<% have_states = !address.country.states.empty? %>
<%= form.label :state do %>
<%= Spree.t(:state) %><abbr class='required' title="required" id=<%="#{address_id}state-required"%>>*</abbr>
<% end %>
<%== state_elements = [
form.collection_select(:state_id, address.country.states,
:id, :name,
{include_blank: true},
{class: have_states ? 'form-control required' : 'form-control hidden',
disabled: !have_states}) +
form.text_field(:state_name,
class: !have_states ? 'form-control required' : 'form-control hidden',
disabled: have_states)
].join.gsub('"', "'").gsub("\n", "")
%>
</p>
<noscript>
<%= form.text_field :state_name, class: 'form-control required' %>
</noscript>
After looking at this post, I thought that :name
is the method being called to generate the text in each option, but when I changed it to :abbr
(which should be a property that it has) everything stayed exactly the same. I am pretty sure that my changes are running since when I make other changes it works. How would you change the option text and managing that, how would you get both the name and abbreviation and concatenate them together with a hyphen.
Just as a note: I am using Deface::Override to make changes to the code.