-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathwidgets.py
More file actions
23 lines (18 loc) · 810 Bytes
/
widgets.py
File metadata and controls
23 lines (18 loc) · 810 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from django import forms
class TipTapAdminWidget(forms.Textarea):
"""
A Textarea whose value is TipTap HTML. The textarea is hidden with CSS;
a TipTap editor is mounted next to it by tiptap-wagtail-widget.jsx.
Wagtail's form submission reads the (JS-kept-in-sync) textarea value
and Django saves it to the body TextField directly.
"""
def __init__(self, *args, **kwargs):
attrs = kwargs.setdefault('attrs', {})
attrs['class'] = (attrs.get('class', '') + ' js-tiptap-admin-field').strip()
attrs['style'] = 'display: none'
super().__init__(*args, **kwargs)
def format_value(self, value):
return value or ''
class Media:
js = ['ubyssey/js/tiptap-wagtail-widget.js']
css = {'all': ['ubyssey/css/tiptap-article.css']}