Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Made country comparison client on country area change event
primal10016b1fccc849e
diff --git a/saleor/static/js/components/address-form.js b/saleor/static/js/components/address-form.jsindex 3d61fd5d44..e3100c6d0e 100644--- a/saleor/static/js/components/address-form.js+++ b/saleor/static/js/components/address-form.js@@ -1,5 +1,4 @@-export default $(document).ready((e) => {- $(function () {+export default $(document).ready((e) => { $(function () {const $i18nAddresses = $('.i18n-address');$i18nAddresses.each(function () {const $form = $(this).closest('form');@@ -9,6 +8,39 @@ export default $(document).ready((e) => {$previewField.val('on');$form.submit();});+ const $countryAreaList = $form.find('#country_area_list');+ if ($countryAreaList){+ const $countryAreaField = $form.find('input[name=country_area]');+ const countryAreaOptions = $countryAreaList.find('option').toArray().reduce((options, option) => {+ option = $(option);+ let value = option.val();+ let text = option.text();+ options.push(value);+ if (option != text) options.push(text);+ return options;+ }, []);+ let countryAreaTimeout = null;+ $countryAreaField.on('change', () => {+ clearTimeout(countryAreaTimeout);+ countryAreaTimeout = setTimeout(() => {+ let lowerCaseValue = $countryAreaField.val().toLowerCase();+ console.log($countryField.val());+ if (lowerCaseValue){+ let value = countryAreaOptions.find(val => val.toLowerCase() == lowerCaseValue);+ if (value) $countryAreaField.val(value);+ else {+ let value = countryAreaOptions.find(val => val.toLowerCase().startsWith(lowerCaseValue));+ if (value) $countryAreaField.val(value);+ else {+ let value = countryAreaOptions.find(val => val.toLowerCase().includes(lowerCaseValue));+ if (value) $countryAreaField.val(value);+ }+ }+ }+ }, 500)+ })+ $countryAreaField.trigger('change');+ }});});diff --git a/saleor/userprofile/widgets.py b/saleor/userprofile/widgets.pyindex 5a6028d251..62f10c33f1 100644--- a/saleor/userprofile/widgets.py+++ b/saleor/userprofile/widgets.py@@ -37,15 +37,4 @@ class DatalistTextWidget(Select):def format_value(self, value):value = super(DatalistTextWidget, self).format_value(value)- value = value[0]- if value:- for choice in self.choices:- if any(c.lower() == value.lower() for c in choice):- return choice[0]- for choice in self.choices:- if any(c.lower().startswith(value.lower()) for c in choice):- return choice[0]- for choice in self.choices:- if any(value.lower() in c.lower() for c in choice):- return choice[0]- return value+ return value[0]