mirror of
https://github.com/wagtail/wagtail.git
synced 2024-11-29 09:33:54 +01:00
implement help_text on chooser blocks
This commit is contained in:
parent
3afe8f4f71
commit
f55b7210ca
@ -306,14 +306,17 @@ class RawHTMLBlock(FieldBlock):
|
||||
|
||||
|
||||
class ChooserBlock(FieldBlock):
|
||||
def __init__(self, required=True, **kwargs):
|
||||
def __init__(self, required=True, help_text=None, **kwargs):
|
||||
self.required = required
|
||||
self.help_text = help_text
|
||||
super(ChooserBlock, self).__init__(**kwargs)
|
||||
|
||||
"""Abstract superclass for fields that implement a chooser interface (page, image, snippet etc)"""
|
||||
@cached_property
|
||||
def field(self):
|
||||
return forms.ModelChoiceField(queryset=self.target_model.objects.all(), widget=self.widget, required=self.required)
|
||||
return forms.ModelChoiceField(
|
||||
queryset=self.target_model.objects.all(), widget=self.widget, required=self.required,
|
||||
help_text=self.help_text)
|
||||
|
||||
def to_python(self, value):
|
||||
# the incoming serialised value should be None or an ID
|
||||
|
@ -1218,7 +1218,7 @@ class TestPageChooserBlock(TestCase):
|
||||
self.assertEqual(block.to_python(None), None)
|
||||
|
||||
def test_form_render(self):
|
||||
block = blocks.PageChooserBlock()
|
||||
block = blocks.PageChooserBlock(help_text="pick a page, any page")
|
||||
|
||||
empty_form_html = block.render_form(None, 'page')
|
||||
self.assertIn('<input id="page" name="page" placeholder="" type="hidden" />', empty_form_html)
|
||||
@ -1227,6 +1227,7 @@ class TestPageChooserBlock(TestCase):
|
||||
christmas_form_html = block.render_form(christmas_page, 'page')
|
||||
expected_html = '<input id="page" name="page" placeholder="" type="hidden" value="%d" />' % christmas_page.id
|
||||
self.assertIn(expected_html, christmas_form_html)
|
||||
self.assertIn("pick a page, any page", christmas_form_html)
|
||||
|
||||
def test_form_response(self):
|
||||
block = blocks.PageChooserBlock()
|
||||
|
Loading…
Reference in New Issue
Block a user