Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix codeclimate issues
primal100e86c812ac293
diff --git a/saleor/static/js/components/address-form.js b/saleor/static/js/components/address-form.jsindex 5a6e4210d5..5f4ae199b1 100644--- a/saleor/static/js/components/address-form.js+++ b/saleor/static/js/components/address-form.js@@ -1,4 +1,5 @@-export default $(document).ready((e) => { $(function () {+export default $(document).ready((e) => {+ $(function () {const $i18nAddresses = $('.i18n-address');$i18nAddresses.each(function () {const $form = $(this).closest('form');@@ -10,36 +11,42 @@ export default $(document).ready((e) => { $(function () {});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;+ 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();- 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);- }- }+ clearTimeout(countryAreaTimeout);+ countryAreaTimeout = setTimeout(() => {+ let lowerCaseValue = $countryAreaField.val().toLowerCase();+ 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)+ }+ }+ }, 500)})$countryAreaField.trigger('change');- }+ };});});diff --git a/saleor/userprofile/i18n.py b/saleor/userprofile/i18n.pyindex 850b9f9c65..250a4df071 100644--- a/saleor/userprofile/i18n.py+++ b/saleor/userprofile/i18n.py@@ -51,6 +51,7 @@ class PossiblePhoneNumberFormField(PhoneNumberField):def to_python(self, value):return value+class CountryAreaChoiceField(forms.ChoiceField):widget = DatalistTextWidgetdiff --git a/saleor/userprofile/widgets.py b/saleor/userprofile/widgets.pyindex 62f10c33f1..d01aa7e32b 100644--- a/saleor/userprofile/widgets.py+++ b/saleor/userprofile/widgets.py@@ -23,6 +23,7 @@ class PhonePrefixWidget(PhoneNumberPrefixWidget):widgets = (Select(attrs=attrs, choices=phone_prefixes), TextInput())super(PhoneNumberPrefixWidget, self).__init__(widgets, attrs)+class DatalistTextWidget(Select):template_name = "userprofile/snippets/datalist.html"input_type = "text"@@ -30,8 +31,8 @@ class DatalistTextWidget(Select):def render(self, *args, **kwargs):return super(DatalistTextWidget, self).render(*args, **kwargs)- def get_context(self, name, value, attrs):- context = super(DatalistTextWidget, self).get_context(name, value, attrs)+ def get_context(self, *args):+ context = super(DatalistTextWidget, self).get_context(*args)context['widget']['type'] = self.input_typereturn context