fields: add support for autocomplete fields in blocks (#44760)
This commit is contained in:
parent
e4b17b5059
commit
a259b9ef54
|
@ -8364,6 +8364,38 @@ def test_block_date(pub, blocks_feature):
|
|||
assert '>2020-06-16<' in resp
|
||||
|
||||
|
||||
def test_block_autocomplete_list(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.ItemField(id='234', required=True, label='Test2', type='item',
|
||||
display_mode='autocomplete', items=['Foo', 'Bar']),
|
||||
]
|
||||
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.form['f1$element0$f234'] = 'Bar'
|
||||
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()
|
||||
assert '>Bar<' in resp
|
||||
|
||||
|
||||
def test_block_multipage(pub, blocks_feature):
|
||||
create_user(pub)
|
||||
FormDef.wipe()
|
||||
|
|
|
@ -239,7 +239,8 @@ class BlockSubWidget(CompositeWidget):
|
|||
|
||||
def add_media(self):
|
||||
for widget in self.get_widgets():
|
||||
widget.add_media()
|
||||
if hasattr(widget, 'add_media'):
|
||||
widget.add_media()
|
||||
|
||||
|
||||
class BlockWidget(WidgetList):
|
||||
|
|
|
@ -1545,7 +1545,9 @@ class ItemField(WidgetField):
|
|||
get_request().form[self.field_key + '_label'] = label_value # :/
|
||||
form.add(StringWidget, self.field_key + '_label', title = self.label,
|
||||
value=label_value, readonly='readonly', size=len(label_value or '')+2)
|
||||
form.get_widget(self.field_key + '_label').field = self
|
||||
form.add(HiddenWidget, self.field_key, value=real_value)
|
||||
form.get_widget(self.field_key).field = self
|
||||
widget = form.get_widget(self.field_key + '_label')
|
||||
if self.extra_css_class:
|
||||
if hasattr(widget, 'extra_css_class') and widget.extra_css_class:
|
||||
|
|
Loading…
Reference in New Issue