{% set countries = craft.commerce.countries.allCountriesAsList %}
{% set states = craft.commerce.states.allStatesAsList %}
{% set modelName = modelName is defined ? modelName : 'address' %}
{% set model = address is defined ? address : null %}
{% if model and model.getErrors('attention') %}
{{ model.getErrors('attention')|join }}
{% endif %}
{% if model and model.getErrors('title') %}
{{ model.getErrors('title')|join }}
{% endif %}
{% if model and model.getErrors('firstName') %}
{{ model.getErrors('firstName')|join }}
{% endif %}
{% if model and model.getErrors('lastName') %}
{{ model.getErrors('lastName')|join }}
{% endif %}
{% if model and model.getErrors('businessName') %}
{{ model.getErrors('businessName')|join }}
{% endif %}
{% if model and model.getErrors('businessTaxId') %}
{{ model.getErrors('businessTaxId')|join }}
{% endif %}
{% if model and model.getErrors('businessId') %}
{{ model.getErrors('businessId')|join }}
{% endif %}
{% if model and model.getErrors('address1') %}
{{ model.getErrors('address1')|join }}
{% endif %}
{% if model and model.getErrors('address2') %}
{{ model.getErrors('address2')|join }}
{% endif %}
{% if model and model.getErrors('city') %}
{{ model.getErrors('city')|join }}
{% endif %}
{% if model and model.getErrors('zipCode') %}
{{ model.getErrors('zipCode')|join }}
{% endif %}
{% if model and model.getErrors('phone') %}
{{ model.getErrors('phone')|join }}
{% endif %}
{% if model and model.getErrors('alternativePhone') %}
{{ model.getErrors('alternativePhone')|join }}
{% endif %}
{% set options = (model and states[model.countryId] is defined ? states[model.countryId] : []) %}
{% if model and model.getErrors('stateValue') %}
{{ model.getErrors('stateValue')|join }}
{% endif %}
{% if model and model.getErrors('countryId') %}
{{ model.getErrors('countryId')|join }}
{% endif %}
{% js %}
var states = {{ craft.commerce.states.allStatesAsList|json_encode|raw }};
$('select.address-country').change(function ()
{
// get the value of the selected country.
var cid = $(this).val();
var $states = $(this).closest('.addressBox').find('select.address-stateId');
var $stateName = $(this).closest('.addressBox').find('input.address-stateName');
$states.find('option').remove();
if (states.hasOwnProperty(cid))
{
// We have states for this country, show the states drop down.
$states.removeClass('hidden');
$states.attr('name', $states.data('modelname')+'[stateValue]');
// We have states for this country, hide the stateName input.
$stateName.removeAttr('name');
$stateName.addClass('hidden');
$stateName.val('');
// Add all states as options to drop down.
for (var id in states[cid])
{
var state = states[cid][id];
var $option = $('');
$option.attr('value', id).text(state);
$states.append($option);
}
}else{
// hide the states dropdown, since this country has none.
$states.addClass('hidden');
$states.removeAttr('name');
// show the stateName
$stateName.removeClass('hidden');
$stateName.attr('name', $stateName.data('modelname')+'[stateValue]');
}
});
$('select').addClass('form-control input-sm');
{% endjs %}