mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-12 01:03:11 +00:00
Merge branch 'expanding-textblock' of https://github.com/davecranwell/wagtail into davecranwell-expanding-textblock
This commit is contained in:
commit
9c1c1ca0d5
3 changed files with 24 additions and 6 deletions
|
|
@ -267,7 +267,8 @@
|
|||
}
|
||||
|
||||
.struct-block .widget-text_input > label,
|
||||
.struct-block .widget-textarea > label{
|
||||
.struct-block .widget-textarea > label,
|
||||
.struct-block .widget-admin_auto_height_text_input > label{
|
||||
display:none;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,18 @@ from wagtail.wagtailcore.models import Page
|
|||
from taggit.forms import TagWidget
|
||||
|
||||
|
||||
class AdminAutoHeightTextInput(WidgetWithScript, widgets.Textarea):
|
||||
def __init__(self, attrs=None):
|
||||
# Use more appropriate rows default, given autoheight will alter this anyway
|
||||
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(id_)
|
||||
|
||||
class AdminDateInput(WidgetWithScript, widgets.DateInput):
|
||||
def render_js_init(self, id_, name, value):
|
||||
return 'initDateChooser({0});'.format(json.dumps(id_))
|
||||
|
|
|
|||
|
|
@ -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)]
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue