Skip to content

Instantly share code, notes, and snippets.

@jsqu99
Created February 14, 2011 18:11
Show Gist options
  • Save jsqu99/826281 to your computer and use it in GitHub Desktop.
Save jsqu99/826281 to your computer and use it in GitHub Desktop.
address without countries
complete contents of checkout/_address.html.erb (w/ hardcoded states/ids...be careful):
<style>
div.inner input[type=text], div.inner select { width: 80%; }
.hidden { display: none; }
</style>
<fieldset id='billing'>
<%= form.fields_for :bill_address do |bill_form| %>
<legend><%= t("billing_address")%></legend>
<div class="inner">
<p class="field">&nbsp;</p>
<p id="bfname" class="field">
<%= bill_form.label :firstname, t(:first_name) %>
<%= bill_form.text_field :firstname, :class => 'required' %><span class="req">*</span>
</p>
<p id="blname" class="field">
<%= bill_form.label :lastname, t(:last_name) %>
<%= bill_form.text_field :lastname, :class => 'required' %><span class="req">*</span>
</p>
<p id="baddress" class="field">
<%= bill_form.label :address1, t(:street_address) %>
<%= bill_form.text_field :address1, :class => 'required' %><span class="req">*</span>
</p>
<p id="baddress2" class="field">
<%= bill_form.label :address2, t(:street_address_2) %>
<%= bill_form.text_field :address2 %>
</p>
<p id="bcity" class="field">
<%= bill_form.label :city, t(:city) %>
<%= bill_form.text_field :city, :class => 'required' %><span class="req">*</span>
</p>
<% if Spree::Config[:address_requires_state] %>
<p class="field">
<span id="bstate">
<% have_states = [email protected]_address.country.states.empty? %>
<%= bill_form.label :state, t(:state) %>
<select class="required" id="order_bill_address_attributes_state_id" name="order[bill_address_attributes][state_id]"><option value=""></option><option value="1061493585">Alabama</option><option value="403740659">Alaska</option><option value="948208802">Arizona</option><option value="471470972">Arkansas</option><option value="276110813">California</option><option value="536031023">Colorado</option><option value="69870734">Connecticut</option><option value="721598219">Delaware</option><option value="6764998">District of Columbia</option><option value="267271847">Florida</option><option value="876916760">Georgia</option><option value="199950338">Hawaii</option><option value="982433740">Idaho</option><option value="625629523">Illinois</option><option value="769938586">Indiana</option><option value="825306985">Iowa</option><option value="969722173">Kansas</option><option value="308473843">Kentucky</option><option value="37199952">Louisiana</option><option value="1055056709">Maine</option><option value="480368357">Maryland</option><option value="385551075">Massachusetts</option><option value="931624400">Michigan</option><option value="1032288924">Minnesota</option><option value="532363768">Mississippi</option><option value="653576146">Missouri</option><option value="999156632">Montana</option><option value="673350891">Nebraska</option><option value="179539703">Nevada</option><option value="426832442">New Hampshire</option><option value="750950030">New Jersey</option><option value="69729944">New Mexico</option><option value="889445952">New York</option><option value="177087202">North Carolina</option><option value="51943165">North Dakota</option><option value="485193526">Ohio</option><option value="248548169">Oklahoma</option><option value="298914262">Oregon</option><option value="471711976">Pennsylvania</option><option value="474001862">Rhode Island</option><option value="597434151">South Carolina</option><option value="615306087">South Dakota</option><option value="726305632">Tennessee</option><option value="525212995">Texas</option><option value="17199670">Utah</option><option value="989115415">Vermont</option><option value="41111624">Virginia</option><option value="414569975">Washington</option><option value="91367981">West Virginia</option><option value="103680699">Wisconsin</option><option value="66390489">Wyoming</option></select>
</span>
<span class="req">*</span>
</p>
<% end %>
<p id="bzip" class="field">
<%= bill_form.label :zipcode, t(:zip) %>
<%= bill_form.text_field :zipcode, :class => 'required' %><span class="req">*</span>
</p>
<input type="hidden" id="order_bill_address_attributes_country_id" name="order[bill_address_attributes][country_id]" value="214"/>
<p id="bphone" class="field">
<%= bill_form.label :phone, t(:phone) %>
<%= bill_form.text_field :phone, :class => 'required' %><span class="req">*</span>
</p>
<% if Spree::Config[:alternative_billing_phone] %>
<p id="baltphone">
<%= bill_form.label :alternative_phone, t(:alternative_phone) %>
<%= bill_form.text_field :alternative_phone %>
</p>
<% end %>
</div>
<% end %>
</fieldset>
<fieldset id='shipping'>
<%= form.fields_for :ship_address do |ship_form| %>
<legend><%= t("shipping_address")%></legend>
<p class="field checkbox">
<label for="order_use_billing" id="use_billing">
<%= check_box_tag 'order[use_billing]', '1', (!(@order.bill_address.empty? && @order.ship_address.empty?) && @order.bill_address.eql?(@order.ship_address)) %> <%= t("use_billing_address") %>
</label>
</p>
<div class="inner">
<p id="sfname" class="field">
<%= ship_form.label :firstname, t(:first_name) %>
<%= ship_form.text_field :firstname, :class => 'required' %><span class="req">*</span>
</p>
<p id="slname" class="field">
<%= ship_form.label :lastname, t(:last_name) %>
<%= ship_form.text_field :lastname, :class => 'required' %><span class="req">*</span>
</p>
<p id="saddress" class="field">
<%= ship_form.label :address1, t(:street_address) %>
<%= ship_form.text_field :address1, :class => 'required' %><span class="req">*</span>
</p>
<p id="saddress2" class="field">
<%= ship_form.label :address2, t(:street_address_2) %>
<%= ship_form.text_field :address2 %>
</p>
<p id="scity" class="field">
<%= ship_form.label :city, t(:city) %>
<%= ship_form.text_field :city, :class => 'required' %><span class="req">*</span>
</p>
<% if Spree::Config[:address_requires_state] %>
<p class="field">
<span id="sstate">
<% have_states = [email protected]_address.country.states.empty? %>
<%= ship_form.label :state, t(:state) %>
<select class="required" id="order_ship_address_attributes_state_id" name="order[ship_address_attributes][state_id]"><option value=""></option><option value="1061493585">Alabama</option><option value="403740659">Alaska</option><option value="948208802">Arizona</option><option value="471470972">Arkansas</option><option value="276110813">California</option><option value="536031023">Colorado</option><option value="69870734">Connecticut</option><option value="721598219">Delaware</option><option value="6764998">District of Columbia</option><option value="267271847">Florida</option><option value="876916760">Georgia</option><option value="199950338">Hawaii</option><option value="982433740">Idaho</option><option value="625629523">Illinois</option><option value="769938586">Indiana</option><option value="825306985">Iowa</option><option value="969722173">Kansas</option><option value="308473843">Kentucky</option><option value="37199952">Louisiana</option><option value="1055056709">Maine</option><option value="480368357">Maryland</option><option value="385551075">Massachusetts</option><option value="931624400">Michigan</option><option value="1032288924">Minnesota</option><option value="532363768">Mississippi</option><option value="653576146">Missouri</option><option value="999156632">Montana</option><option value="673350891">Nebraska</option><option value="179539703">Nevada</option><option value="426832442">New Hampshire</option><option value="750950030">New Jersey</option><option value="69729944">New Mexico</option><option value="889445952">New York</option><option value="177087202">North Carolina</option><option value="51943165">North Dakota</option><option value="485193526">Ohio</option><option value="248548169">Oklahoma</option><option value="298914262">Oregon</option><option value="471711976">Pennsylvania</option><option value="474001862">Rhode Island</option><option value="597434151">South Carolina</option><option value="615306087">South Dakota</option><option value="726305632">Tennessee</option><option value="525212995">Texas</option><option value="17199670">Utah</option><option value="989115415">Vermont</option><option value="41111624">Virginia</option><option value="414569975">Washington</option><option value="91367981">West Virginia</option><option value="103680699">Wisconsin</option><option value="66390489">Wyoming</option></select>
</span>
<span class="req">*</span>
</p>
<% end %>
<p id="szip" class="field">
<%= ship_form.label :zipcode, t(:zip) %>
<%= ship_form.text_field :zipcode, :class => 'required' %><span class="req">*</span>
</p>
<input type="hidden" id="order_ship_address_attributes_country_id" name="order[ship_address_attributes][country_id]" value="214"/>
<p id="sphone" class="field">
<%= ship_form.label :phone, t(:phone) %>
<%= ship_form.text_field :phone, :class => 'required' %><span class="req">*</span>
</p>
<% if Spree::Config[:alternative_shipping_phone] %>
<p id="saltphone">
<%= ship_form.label :alternative_phone, t(:alternative_phone) %>
<%= ship_form.text_field :alternative_phone %>
</p>
<% end %>
</div>
<% end %>
</fieldset>
<hr class="space" />
<div class="form-buttons">
<input type="submit" class="continue button primary" value="<%=t("save_and_continue") %>" />
</div>
(function($){
$(document).ready(function(){
$('#checkout_form_address').validate();
var get_states = function(region){
var country = $('span#' + region + 'country :only-child').val();
return state_mapper[country];
}
var update_state = function(region) {
var states = get_states(region);
var state_select = $('span#' + region + 'state select');
var state_input = $('span#' + region + 'state input');
if(states) {
var selected = state_select.val();
state_select.html('');
var states_with_blank = [["",""]].concat(states);
$.each(states_with_blank, function(pos,id_nm) {
var opt = $(document.createElement('option'))
.attr('value', id_nm[0])
.html(id_nm[1]);
if(selected==id_nm[0]){
opt.attr('selected', 'selected');
}
state_select.append(opt);
});
state_select.removeAttr('disabled').show();
state_input.hide().attr('disabled', 'disabled');
} else {
state_input.removeAttr('disabled').show();
state_select.hide().attr('disabled', 'disabled');
}
};
// Show fields for the selected payment method
$("input[type='radio'][name='order[payments_attributes][][payment_method_id]']").click(function(){
$('#payment-methods li').hide();
if(this.checked){ $('#payment_method_'+this.value).show(); }
}).triggerHandler('click');
/* $('span#bcountry select').change(function() { update_state('b'); });
$('span#scountry select').change(function() { update_state('s'); });
update_state('b');
update_state('s');
*/
$('input#order_use_billing').click(function() {
if($(this).is(':checked')) {
$('#shipping .inner input, #shipping .inner select, #shipping .inner label, #shipping .inner .req').hide();
$('#shipping .inner input, #shipping .inner select').attr('disabled', 'disabled');
} else {
$('#shipping .inner input, #shipping .inner select, #shipping .inner label, #shipping .inner .req').show();
$('#shipping .inner input, #shipping .inner select').removeAttr('disabled', 'disabled');
//only want to enable relevant field
/* if(get_states('s')){
$('span#sstate input').hide().attr('disabled', 'disabled');
}else{
$('span#sstate select').hide().attr('disabled', 'disabled');
}
*/
}
}).triggerHandler('click');
$('form.edit_checkout').submit(function() {
$(this).find(':submit, :image').attr('disabled', true).removeClass('primary').addClass('disabled');
});
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment