0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-12-01 11:41:20 +01:00

initial work on allowing jquery.autosize to work with our new streamfield textblock

This commit is contained in:
Dave Cranwell 2015-03-03 17:43:45 +00:00
parent 15e6336db6
commit 27c605c00f
2 changed files with 21 additions and 5 deletions

View File

@ -15,6 +15,17 @@ from wagtail.wagtailcore.models import Page
from taggit.forms import TagWidget
class AdminAutoHeightTextInput(WidgetWithScript, widgets.Textarea):
def __init__(self, attrs=None):
# Use slightly better defaults than HTML's 20x2 box
default_attrs = {'rows': '1'}
if attrs:
default_attrs.update(attrs)
super(AdminAutoHeightTextInput, self).__init__(default_attrs)
def render_js_init(self, id_, name, value):
return '$("#{0}").autosize();'.format(json.dumps(id_))
class AdminDateInput(WidgetWithScript, widgets.DateInput):
def render_js_init(self, id_, name, value):
return 'initDateChooser({0});'.format(json.dumps(id_))

View File

@ -68,13 +68,18 @@ class CharBlock(FieldBlock):
class TextBlock(FieldBlock):
def __init__(self, required=True, help_text=None, max_length=None, min_length=None, **kwargs):
self.field = forms.CharField(
widget=forms.Textarea(),
required=required, help_text=help_text,
max_length=max_length, min_length=min_length)
def __init__(self, required=True, help_text=None, rows=1, max_length=None, min_length=None, **kwargs):
self.field_options = {'required': required, 'help_text': help_text, 'max_length': max_length, 'min_length': min_length}
self.rows = rows
super(TextBlock, self).__init__(**kwargs)
@cached_property
def field(self):
from wagtail.wagtailadmin.widgets import AdminAutoHeightTextInput
field_kwargs = {'widget': AdminAutoHeightTextInput(attrs={'rows':self.rows})}
field_kwargs.update(self.field_options)
return forms.CharField(**field_kwargs)
def get_searchable_content(self, value):
return [force_text(value)]