Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add warning if SEO input is too short
Pacu21a2a8c37fbd2
diff --git a/saleor/dashboard/collection/forms.py b/saleor/dashboard/collection/forms.pyindex 1b54230f09..c7f0fba890 100644--- a/saleor/dashboard/collection/forms.py+++ b/saleor/dashboard/collection/forms.py@@ -30,6 +30,11 @@ class CollectionForm(forms.ModelForm):widgets = {'seo_description': CharsLeftWidget,'seo_title': CharsLeftWidget}+ help_texts = {+ 'seo_description': pgettext_lazy(+ 'Form field help text',+ 'Slug is being used to create page URL'),+ 'seo_title': 'Example help text'}def __init__(self, *args, **kwargs):super().__init__(*args, **kwargs)@@ -38,11 +43,13 @@ class CollectionForm(forms.ModelForm):self.fields['seo_description'].widget.attrs.update({'id': 'seo_description','data-bind': '',- 'placeholder': ''})+ 'placeholder': '',+ 'min-recommended-length': 130})self.fields['seo_title'].widget.attrs.update({'id': 'seo_title','data-bind': self['name'].auto_id,- 'placeholder': self.instance.name})+ 'placeholder': self.instance.name,+ 'min-recommended-length': 40})def save(self, commit=True):self.instance.slug = slugify(unidecode(self.instance.name))diff --git a/saleor/static/dashboard/js/components/google-preview.js b/saleor/static/dashboard/js/components/google-preview.jsindex 2c30ee5cc7..de246b5217 100644--- a/saleor/static/dashboard/js/components/google-preview.js+++ b/saleor/static/dashboard/js/components/google-preview.js@@ -26,6 +26,15 @@ function updateCharsCount(field) {const $fieldId = field.attr('id');const $charCount = $(`span[data-bind=${$fieldId}]`);const $fieldLength = field.val().length || field.attr('placeholder').length;+ const $minRecommendedLength = field.attr('min-recommended-length');+ const $charCountWrapper = $charCount.parent();+ if ($fieldLength < $minRecommendedLength) {+ $charCountWrapper.addClass('red-text');+ $charCountWrapper.removeClass('green-text');+ } else if ($charCountWrapper.hasClass('red-text')) {+ $charCountWrapper.removeClass('red-text');+ $charCountWrapper.addClass('green-text');+ }$charCount.text($fieldLength);}