Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add RichTextField widget

dominik-zeglen6fe6b2ddbdde
diff --git a/saleor/dashboard/product/forms.py b/saleor/dashboard/product/forms.py
index d1a45dfb40..56888bc094 100644
--- a/saleor/dashboard/product/forms.py
+++ b/saleor/dashboard/product/forms.py
@@ -11,6 +11,7 @@ from ...product.models import (
ProductImage, ProductVariant, Stock, StockLocation, VariantImage)
from .widgets import ImagePreviewWidget
from . import ProductBulkAction
+from ..widgets import RichTextEditorWidget
class ProductClassSelectorForm(forms.Form):
@@ -137,6 +138,7 @@ class ProductForm(forms.ModelForm):
self.product_attributes = self.product_attributes.prefetch_related(
'values')
self.prepare_fields_for_attributes()
+ self.fields['description'].widget = RichTextEditorWidget()
def prepare_fields_for_attributes(self):
for attribute in self.product_attributes:
diff --git a/saleor/dashboard/widgets.py b/saleor/dashboard/widgets.py
index bd0629bd44..f5f8cca7fa 100644
--- a/saleor/dashboard/widgets.py
+++ b/saleor/dashboard/widgets.py
@@ -1,5 +1,6 @@
from django import forms
from django.conf import settings
+from django.forms import Textarea
from django_filters.widgets import RangeWidget
from django_prices.widgets import PriceInput
@@ -22,3 +23,11 @@ class PriceRangeWidget(RangeWidget):
class PhonePrefixWidget(StorefrontPhonePrefixWidget):
template_name = 'dashboard/order/widget/phone_prefix_widget.html'
+
+
+class RichTextEditorWidget(Textarea):
+ def __init__(self, attrs=None):
+ default_attrs = {'class': 'rich-text-editor'}
+ if attrs:
+ default_attrs.update(attrs)
+ super(Textarea, self).__init__(default_attrs)
diff --git a/saleor/static/dashboard/js/components/misc.js b/saleor/static/dashboard/js/components/misc.js
index 4853272739..cddeaa540e 100644
--- a/saleor/static/dashboard/js/components/misc.js
+++ b/saleor/static/dashboard/js/components/misc.js
@@ -61,7 +61,7 @@ $('#product-is-published').on('click', (e) => {
});
// WYSIWYG editor
-const editor = new MediumEditor('#id_description');
+new MediumEditor('.rich-text-editor');
// Styleguide sticky right menu
onScroll(() => $('.styleguide__menu').toggleClass('fixed', $(window).scrollTop() > 100));
diff --git a/saleor/static/dashboard/scss/components/_medium-editor.scss b/saleor/static/dashboard/scss/components/_rich-text-editor.scss
similarity index 100%
rename from saleor/static/dashboard/scss/components/_medium-editor.scss
rename to saleor/static/dashboard/scss/components/_rich-text-editor.scss
diff --git a/saleor/static/dashboard/scss/dashboard.scss b/saleor/static/dashboard/scss/dashboard.scss
index 7685a64520..e07dc39019 100644
--- a/saleor/static/dashboard/scss/dashboard.scss
+++ b/saleor/static/dashboard/scss/dashboard.scss
@@ -14,12 +14,12 @@
@import "components/form";
@import "components/formset";
@import "components/list";
-@import "components/medium-editor";
@import "components/nav";
@import "components/pagination";
@import "components/modals";
@import "components/product-gallery";
@import "components/ppoi";
+@import "components/rich-text-editor";
@import "components/select2";
@import "components/search";
@import "components/tabs";