fields: add support for inert fields in blocks (#44760)
This commit is contained in:
parent
a259b9ef54
commit
efbadb06b5
|
@ -8396,6 +8396,36 @@ def test_block_autocomplete_list(pub, blocks_feature):
|
|||
assert '>Bar<' in resp
|
||||
|
||||
|
||||
def test_block_title_and_comment(pub, blocks_feature):
|
||||
create_user(pub)
|
||||
FormDef.wipe()
|
||||
BlockDef.wipe()
|
||||
|
||||
block = BlockDef()
|
||||
block.name = 'foobar'
|
||||
block.fields = [
|
||||
fields.StringField(id='123', required=True, label='Test', type='string'),
|
||||
fields.TitleField(id='234', label='Blah', type='title'),
|
||||
fields.CommentField(id='345', label='Blah', type='comment'),
|
||||
]
|
||||
block.store()
|
||||
|
||||
formdef = FormDef()
|
||||
formdef.name = 'form title'
|
||||
formdef.fields = [
|
||||
fields.BlockField(id='1', label='test', type='block:foobar'),
|
||||
]
|
||||
formdef.store()
|
||||
|
||||
app = get_app(pub)
|
||||
resp = app.get(formdef.get_url())
|
||||
resp.form['f1$element0$f123'] = 'foo'
|
||||
resp = resp.form.submit('submit') # -> validation page
|
||||
assert 'Check values then click submit.' in resp.text
|
||||
resp = resp.form.submit('submit') # -> submit
|
||||
resp = resp.follow()
|
||||
|
||||
|
||||
def test_block_multipage(pub, blocks_feature):
|
||||
create_user(pub)
|
||||
FormDef.wipe()
|
||||
|
|
|
@ -218,7 +218,8 @@ class BlockSubWidget(CompositeWidget):
|
|||
|
||||
def set_value(self, value):
|
||||
for widget in self.get_widgets():
|
||||
widget.set_value(value.get(widget.field.id))
|
||||
if hasattr(widget, 'set_value'):
|
||||
widget.set_value(value.get(widget.field.id))
|
||||
|
||||
def get_field_data(self, field, widget):
|
||||
from wcs.formdef import FormDef
|
||||
|
|
|
@ -650,6 +650,7 @@ class TitleField(Field):
|
|||
)
|
||||
label = wcs.workflows.template_on_formdata(None, self.label, autoescape=False)
|
||||
widget = HtmlWidget(htmltext(title_markup) % label)
|
||||
widget.field = self
|
||||
form.widgets.append(widget)
|
||||
return widget
|
||||
add_to_view_form = add_to_form
|
||||
|
@ -700,11 +701,12 @@ class CommentField(Field):
|
|||
content=self.get_text(),
|
||||
extra_css_class=self.extra_css_class)
|
||||
form.widgets.append(widget)
|
||||
widget.field = self
|
||||
return widget
|
||||
|
||||
def add_to_view_form(self, *args):
|
||||
def add_to_view_form(self, *args, **kwargs):
|
||||
if self.include_in_validation_page:
|
||||
return self.add_to_form(*args)
|
||||
return self.add_to_form(*args, **kwargs)
|
||||
return None
|
||||
|
||||
def get_html_content(self):
|
||||
|
@ -2013,7 +2015,7 @@ class PageField(Field):
|
|||
changed = True
|
||||
return changed
|
||||
|
||||
def add_to_view_form(self, *args):
|
||||
def add_to_view_form(self, *args, **kwargs):
|
||||
pass
|
||||
|
||||
register_field_class(PageField)
|
||||
|
|
Loading…
Reference in New Issue