Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add charsleft widget
Pacu2d3373daddc6f
diff --git a/saleor/dashboard/collection/forms.py b/saleor/dashboard/collection/forms.pyindex 586bdd1a6c..1b54230f09 100644--- a/saleor/dashboard/collection/forms.py+++ b/saleor/dashboard/collection/forms.py@@ -28,8 +28,8 @@ class CollectionForm(forms.ModelForm):'Products selection','Background Image')}widgets = {- 'seo_description': CharsLeftWidget- }+ 'seo_description': CharsLeftWidget,+ 'seo_title': CharsLeftWidget}def __init__(self, *args, **kwargs):super().__init__(*args, **kwargs)diff --git a/saleor/dashboard/widgets.py b/saleor/dashboard/widgets.pyindex f60e9b76fd..0e696a8796 100644--- a/saleor/dashboard/widgets.py+++ b/saleor/dashboard/widgets.py@@ -37,4 +37,7 @@ class RichTextEditorWidget(Textarea):class CharsLeftWidget(TextInput):+ """Displays number of characters left on the right side of the label,+ requires different rendering on the frontend.+ """passdiff --git a/saleor/static/dashboard/js/components/google-preview.js b/saleor/static/dashboard/js/components/google-preview.jsindex dbfd25d1ca..2c30ee5cc7 100644--- a/saleor/static/dashboard/js/components/google-preview.js+++ b/saleor/static/dashboard/js/components/google-preview.js@@ -17,11 +17,18 @@ if ($descriptionMaterialize) {const $googleTitlePreview = $('#google-preview-title');const $googleDescriptionPreview = $('#google-preview-description');-const $preview = $('.preview');+const $preview = $('#google-preview');const $previewErrors = $('#preview-error');const watchedEvents = 'input propertychange cut paste copy change';+function updateCharsCount(field) {+ const $fieldId = field.attr('id');+ const $charCount = $(`span[data-bind=${$fieldId}]`);+ const $fieldLength = field.val().length || field.attr('placeholder').length;+ $charCount.text($fieldLength);+}+function checkForErrors() {const $descriptionText = $googleDescriptionPreview.text();const $titleText = $googleTitlePreview.text();@@ -58,6 +65,7 @@ function updatePlaceholderOnInput(field, seoField, previewField) {previewField.text(truncate($placeholderText, seoField));}checkForErrors();+ updateCharsCount(seoField);});}@@ -72,6 +80,7 @@ function updatePreviewOnInput(seoField, previewField) {previewField.text(truncate($placeholderValue, seoField));}checkForErrors();+ updateCharsCount(seoField);});}@@ -82,3 +91,5 @@ if ($description) {}updatePreviewOnInput($seoTitle, $googleTitlePreview);updatePreviewOnInput($seoDescription, $googleDescriptionPreview);+updateCharsCount($seoTitle);+updateCharsCount($seoDescription);diff --git a/saleor/static/dashboard/scss/components/_google-preview.scss b/saleor/static/dashboard/scss/components/_google-preview.scssindex d722fd3723..017619d886 100644--- a/saleor/static/dashboard/scss/components/_google-preview.scss+++ b/saleor/static/dashboard/scss/components/_google-preview.scss@@ -1,42 +1,42 @@.google-preview {- text-align: left;- letter-spacing: initial;+ text-align: left;+ letter-spacing: initial;- .container {- margin: 12px;- background-color: #fff;- max-width: 600px;- .title {- display: block;- text-overflow: ellipsis;- margin-bottom: 2px;- a {- color: rgb(26, 13, 171);- cursor: pointer;- font-size: 18px;- line-height: 21px;- text-decoration: none solid rgb(26, 13, 171);- &:hover {- text-decoration: underline;- }- word-wrap: break-word;- overflow-wrap: break-word;- }- }- .description {- color: rgb(84, 84, 84);- font-size: 13px;- line-height: 18px;- overflow-wrap: break-word;- }- .url {- color: rgb(0, 102, 33);- font-size: 13px;- line-height: 16px;- white-space: nowrap;- margin-bottom: 2px;- overflow: hidden;- text-overflow: ellipsis;+ &__container {+ margin: 12px;+ background-color: #fff;+ max-width: 600px;+ }+ &__title {+ display: block;+ text-overflow: ellipsis;+ margin-bottom: 2px;+ a {+ color: rgb(26, 13, 171);+ cursor: pointer;+ font-size: 18px;+ line-height: 21px;+ text-decoration: none solid rgb(26, 13, 171);+ &:hover {+ text-decoration: underline;+ }+ word-wrap: break-word;+ overflow-wrap: break-word;}}+ &__description {+ color: rgb(84, 84, 84);+ font-size: 13px;+ line-height: 18px;+ overflow-wrap: break-word;+ }+ &__url {+ color: rgb(0, 102, 33);+ font-size: 13px;+ line-height: 16px;+ white-space: nowrap;+ margin-bottom: 2px;+ overflow: hidden;+ text-overflow: ellipsis;+ }}diff --git a/saleor/static/dashboard/scss/dashboard.scss b/saleor/static/dashboard/scss/dashboard.scssindex bf126f08fa..c36fd9dfff 100644--- a/saleor/static/dashboard/scss/dashboard.scss+++ b/saleor/static/dashboard/scss/dashboard.scss@@ -13,6 +13,7 @@@import "components/dropzone";@import "components/form";@import "components/formset";+@import "components/google-preview";@import "components/list";@import "components/nav";@import "components/pagination";@@ -26,7 +27,6 @@@import "components/tabs";@import "components/timeline";@import "components/zero-page";-@import "components/google-preview";@import "layouts/orders";@import "layouts/search-results";diff --git a/templates/dashboard/includes/_google_preview.html b/templates/dashboard/includes/_google_preview.htmlindex 66d7f7909e..9d4a8b6372 100644--- a/templates/dashboard/includes/_google_preview.html+++ b/templates/dashboard/includes/_google_preview.html@@ -3,20 +3,22 @@{% load i18n %}<div class='google-preview'>- <div class='container'>+ <div class='google-preview__container'><p class="flow-text">Search engine listing preview</p><br><div id="preview-error"></div>- <div class="preview">- <div class='title'>+ <div id="google-preview">+ <div class='google-preview__title'><a id="google-preview-title" href='#'>{{ object.seo_title|default:form.seo_title.field.widget.attrs.placeholder }}</a></div>- {% if object.pk %}- <div class='url'>{% build_absolute_uri request=request location=object.get_absolute_url %}</div>- {% else %}- <div class='url'>{% build_absolute_uri request=request location="/" %}</div>- {% endif %}- <div id="google-preview-description" class='description'>{{ object.seo_description|default:form.seo_description.field.widget.attrs.placeholder }}</div>+ <div class='google-preview__url'>+ {% if object.pk %}+ {% build_absolute_uri request=request location=object.get_absolute_url %}+ {% else %}+ {% build_absolute_uri request=request location="/" %}+ {% endif %}+ </div>+ <div id="google-preview-description" class='google-preview__description'>{{ object.seo_description|default:form.seo_description.field.widget.attrs.placeholder }}</div></div></div></div>diff --git a/templates/materializecssform/field.html b/templates/materializecssform/field.htmlindex ee68a97adf..b6b5a5354b 100644--- a/templates/materializecssform/field.html+++ b/templates/materializecssform/field.html@@ -343,8 +343,13 @@{% trans "(optional)" context "Dashboard form labels" %}{% endif %}</label>- <span class="chars-left__count {{ field.auto_id }}">10 out of 10 chars used</span>- </div>+ <span class="chars-left__count">+ <span class="chars-left__count__current" data-bind="{{ field.field.widget.attrs.id }}">+ {% blocktrans with current_chars_count=field.value|length max_chars_count=field.field.max_length %}+ {{ current_chars_count }}</span> of {{ max_chars_count }} characters used+ {% endblocktrans %}+ </span>+ </div>{{ field }}{% for error in field.errors %}<p class="help-block materialize-red-text">{{ error }}</p>