Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Improve address forms
Patryk Zawadzkie738b5c0901d
diff --git a/saleor/checkout/templates/checkout/address_form.html b/saleor/checkout/templates/checkout/address_form.htmlindex bd64836ba1..d62545ad35 100644--- a/saleor/checkout/templates/checkout/address_form.html+++ b/saleor/checkout/templates/checkout/address_form.html@@ -45,27 +45,48 @@{% endif %}</div></div>+ <br>{% endif %}{% endwith %}-<div class="conditional-visibility" data-controller="input[name={{ addresses_form.address.html_name }}]" data-value="">- <br>- {% if display_email_form %}- {{ step.forms.email|as_vertical_form }}- {% endif %}-+<div class="conditional-visibility" data-controller="input[name={{ addresses_form.address.html_name }}]" data-value="{{ addresses_form.address.field.new_choice_value }}">{% with new_address=step.forms.new_address %}- <div class="i18n-address" data-address-url="{% static 'js/address.json' %}" data-lang="{{ LANGUAGE_CODE }}" data-prefix="{{ new_address.prefix }}">- {{ new_address.first_name|as_vertical_form }}- {{ new_address.last_name|as_vertical_form }}- {{ new_address.company_name|as_vertical_form }}- {{ new_address.street_address_1|as_vertical_form }}- {{ new_address.street_address_2|as_vertical_form }}- {{ new_address.city|as_vertical_form }}- {{ new_address.city_area|as_vertical_form }}- {{ new_address.postal_code|as_vertical_form }}- {{ new_address.country|as_vertical_form }}- {{ new_address.country_area|as_vertical_form }}+ <div class="row">+ <div class="col-sm-6">+ {{ new_address.first_name|as_vertical_form }}+ </div>+ <div class="col-sm-6">+ {{ new_address.last_name|as_vertical_form }}+ </div>+ </div>+ {{ new_address.company_name|as_vertical_form }}+ <div class="row">+ <div class="col-sm-8">+ {{ new_address.street_address_1|as_vertical_form }}+ </div>+ <div class="col-sm-4">+ {{ new_address.street_address_2|as_vertical_form }}+ </div>+ </div>+ <div class="row">+ <div class="col-sm-6">+ {{ new_address.city|as_vertical_form }}+ </div>+ <div class="col-sm-6">+ {{ new_address.city_area|as_vertical_form }}+ </div>+ </div>+ <div class="row">+ <div class="col-sm-8">+ {{ new_address.country_area|as_vertical_form }}+ </div>+ <div class="col-sm-4">+ {{ new_address.postal_code|as_vertical_form }}+ </div></div>+ {{ new_address.country|as_vertical_form }}+ {% if display_email_form %}+ {{ step.forms.email|as_vertical_form }}+ {% endif %}{{ new_address.phone|as_vertical_form }}{% endwith %}</div>diff --git a/saleor/checkout/templates/checkout/details.html b/saleor/checkout/templates/checkout/details.htmlindex 8becc1f65d..3976a81a59 100644--- a/saleor/checkout/templates/checkout/details.html+++ b/saleor/checkout/templates/checkout/details.html@@ -51,6 +51,8 @@{% endfor %}</ul>+ <br>+{% block forms %}{% endblock %}</div>diff --git a/saleor/checkout/templates/checkout/shipping_address.html b/saleor/checkout/templates/checkout/shipping_address.htmlindex c443a76f0e..eaebcd467a 100644--- a/saleor/checkout/templates/checkout/shipping_address.html+++ b/saleor/checkout/templates/checkout/shipping_address.html@@ -6,6 +6,7 @@<form method="post">{% csrf_token %}<h4>{% trans "Shipping address" %}</h4>+ <br>{% if user.is_authenticated %}{% include "checkout/address_form.html" with addresses_form=step.forms.addresses_form %}{% else %}diff --git a/saleor/checkout/templates/checkout/shipping_method.html b/saleor/checkout/templates/checkout/shipping_method.htmlindex 1df42156a8..a34190edfa 100644--- a/saleor/checkout/templates/checkout/shipping_method.html+++ b/saleor/checkout/templates/checkout/shipping_method.html@@ -7,6 +7,7 @@<form method="post">{% csrf_token %}<h4>{% trans "Shipping method" %}</h4>+ <br><div class="row"><div class="btn-group-vertical col-sm-12" data-toggle="buttons">{% with shipping_form=step.forms.shipping %}diff --git a/saleor/checkout/templates/checkout/summary.html b/saleor/checkout/templates/checkout/summary.htmlindex b430920aea..60aa7d6e91 100644--- a/saleor/checkout/templates/checkout/summary.html+++ b/saleor/checkout/templates/checkout/summary.html@@ -8,6 +8,7 @@<form method="post">{% csrf_token %}<h4>{% trans "Billing address" %}</h4>+ <br>{% include "checkout/address_form.html" with addresses_form=step.forms.addresses_form %}<br><p class="text-right">diff --git a/saleor/static/js_src/storefront.jsx b/saleor/static/js_src/storefront.jsxindex 70f5cb943a..b517982b89 100644--- a/saleor/static/js_src/storefront.jsx+++ b/saleor/static/js_src/storefront.jsx@@ -238,3 +238,25 @@ var $formFullToggle = $("#form-full-toggle");if ($formFullToggle.length) {React.render(<FormShippingToggler label={$formFullToggle.data("label")} />, document.getElementById("form-full-toggle"));}++$(function() {+ $('.conditional-visibility').each(function() {+ let $element = $(this);+ let controller = $element.data('controller');+ let triggerValue = $element.data('value');+ let $controller = $(controller);+ function updateVisiblity() {+ let value = $controller.filter(':checked').val();+ if (!value && $controller.prop('type') === 'hidden') {+ value = $controller.val();+ }+ if (value === triggerValue) {+ $element.show();+ } else {+ $element.hide();+ }+ }+ $controller.on('change', updateVisiblity);+ updateVisiblity();+ });+});diff --git a/saleor/userprofile/models.py b/saleor/userprofile/models.pyindex 88777a6662..e46e13633b 100644--- a/saleor/userprofile/models.py+++ b/saleor/userprofile/models.py@@ -37,19 +37,19 @@ class Address(models.Model):pgettext_lazy('Address field', 'last name'),max_length=256)company_name = models.CharField(- pgettext_lazy('Address field', 'company name'),+ pgettext_lazy('Address field', 'company or organization'),max_length=256, blank=True)street_address_1 = models.CharField(- pgettext_lazy('Address field', 'street address 1'),+ pgettext_lazy('Address field', 'address'),max_length=256)street_address_2 = models.CharField(- pgettext_lazy('Address field', 'street address 2'),+ pgettext_lazy('Address field', 'address'),max_length=256, blank=True)city = models.CharField(pgettext_lazy('Address field', 'city'),max_length=256)city_area = models.CharField(- pgettext_lazy('Address field', 'city administrative area'),+ pgettext_lazy('Address field', 'district'),max_length=128, blank=True)postal_code = models.CharField(pgettext_lazy('Address field', 'postal code'),@@ -58,7 +58,7 @@ class Address(models.Model):pgettext_lazy('Address field', 'country'),choices=COUNTRY_CHOICES, max_length=2)country_area = models.CharField(- pgettext_lazy('Address field', 'country administrative area'),+ pgettext_lazy('Address field', 'state or province'),max_length=128, blank=True)phone = models.CharField(pgettext_lazy('Address field', 'phone number'),