From aa0aacfb0419d74c13690bb70a1bc9d2890a1829 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Sun, 9 Aug 2020 11:13:55 +0200 Subject: [PATCH] forms: add list-add class to "add item" widget (#45688) --- tests/test_form_pages.py | 1 + wcs/qommon/form.py | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/test_form_pages.py b/tests/test_form_pages.py index 5eeb8a0f9..b574e4d0f 100644 --- a/tests/test_form_pages.py +++ b/tests/test_form_pages.py @@ -8655,6 +8655,7 @@ def test_block_repeated(pub, blocks_feature): assert resp.text.count('>Test<') == 1 assert resp.text.count('>hintblock<') == 1 assert 'Add another' in resp + assert resp.html.find('div', {'class': 'list-add'}) resp = resp.form.submit('f1$add_element') assert resp.text.count('>Test<') == 2 assert resp.text.count('>hintblock<') == 1 diff --git a/wcs/qommon/form.py b/wcs/qommon/form.py index 30e85d871..9b6623611 100644 --- a/wcs/qommon/form.py +++ b/wcs/qommon/form.py @@ -237,6 +237,10 @@ TextWidget.render_content = text_render_content class SubmitWidget(quixote.form.widget.SubmitWidget): + def __init__(self, *args, **kwargs): + self.extra_css_class = kwargs.pop('extra_css_class', None) + super().__init__(*args, **kwargs) + def render_content(self): if self.name in ('cancel', 'previous', 'save-draft'): self.attrs['formnovalidate'] = 'formnovalidate' @@ -387,7 +391,7 @@ class Form(QuixoteForm): r = TemplateIO(html=True) classnames = '%s widget %s-button %s' % ( button.__class__.__name__, button.name, - getattr(button, 'extra_css_class', '')) + getattr(button, 'extra_css_class', None) or '') r += htmltext('
') % classnames r += htmltext('
') r += button.render_content()