Updated form widgets group interface to add fieldset class
authorThierry Florac <thierry.florac@onf.fr>
Thu, 21 Sep 2017 14:29:32 +0200
changeset 66 b4ebe523bb4e
parent 65 e5dd3518be91
child 67 9c2648bc7076
Updated form widgets group interface to add fieldset class
src/pyams_form/group.py
src/pyams_form/interfaces/form.py
src/pyams_form/templates/form.pt
src/pyams_form/templates/inner-form.pt
src/pyams_form/templates/widget-form.pt
--- a/src/pyams_form/group.py	Wed Sep 20 12:13:36 2017 +0200
+++ b/src/pyams_form/group.py	Thu Sep 21 14:29:32 2017 +0200
@@ -33,6 +33,7 @@
     id = FieldProperty(IFormWidgetsGroup['id'])
     widgets = FieldProperty(IFormWidgetsGroup['widgets'])
     bordered = FieldProperty(IFormWidgetsGroup['bordered'])
+    fieldset_class = FieldProperty(IFormWidgetsGroup['fieldset_class'])
     legend = FieldProperty(IFormWidgetsGroup['legend'])
     help = FieldProperty(IFormWidgetsGroup['help'])
     _css_class = FieldProperty(IFormWidgetsGroup['css_class'])
@@ -44,13 +45,15 @@
     hide_if_empty = FieldProperty(IFormWidgetsGroup['hide_if_empty'])
     subforms_legend = FieldProperty(IFormWidgetsGroup['subforms_legend'])
 
-    def __init__(self, form, id, widgets=None, bordered=True, legend=None, help=None, css_class='', switch=False,
-                 checkbox_switch=False, checkbox_field=None, checkbox_mode='hide', hide_if_empty=False):
+    def __init__(self, form, id, widgets=None, bordered=True, fieldset_class=None, legend=None, help=None,
+                 css_class='', switch=False, checkbox_switch=False, checkbox_field=None, checkbox_mode='hide',
+                 hide_if_empty=False):
         assert (not checkbox_switch) or checkbox_field, "You must define checkbox field when using checkbox switch"
         self.form = form
         self.id = id
         self.widgets = widgets or []
         self.bordered = bordered
+        self.fieldset_class = fieldset_class
         self.legend = legend
         self.help = help
         self._css_class = css_class
@@ -111,7 +114,7 @@
 
     @property
     def switcher_state(self):
-        return 'on' if self.visible else 'off'
+        return 'open' if self.visible else 'off'
 
     @property
     def checker_state(self):
@@ -126,11 +129,12 @@
                       key=get_form_weight)
 
 
-def NamedWidgetsGroup(form, id, widgets, names=(), bordered=True, legend=None, help=None, css_class='', switch=False,
-                      checkbox_switch=False, checkbox_field=None, checkbox_mode='hide', hide_if_empty=False):
+def NamedWidgetsGroup(form, id, widgets, names=(), bordered=True, fieldset_class=None, legend=None, help=None,
+                      css_class='', switch=False, checkbox_switch=False, checkbox_field=None, checkbox_mode='hide',
+                      hide_if_empty=False):
     """Create a widgets group based on widgets names"""
-    return FormWidgetsGroup(form, id, [widgets.get(name) for name in names], bordered, legend, help, css_class, switch,
-                            checkbox_switch, checkbox_field, checkbox_mode, hide_if_empty)
+    return FormWidgetsGroup(form, id, [widgets.get(name) for name in names], bordered, fieldset_class, legend, help,
+                            css_class, switch, checkbox_switch, checkbox_field, checkbox_mode, hide_if_empty)
 
 
 @implementer(IGroupsBasedForm)
--- a/src/pyams_form/interfaces/form.py	Wed Sep 20 12:13:36 2017 +0200
+++ b/src/pyams_form/interfaces/form.py	Thu Sep 21 14:29:32 2017 +0200
@@ -193,6 +193,9 @@
     bordered = Bool(title="Bordered fieldset",
                     required=False)
 
+    fieldset_class = TextLine(title="Fieldset class",
+                              required=False)
+
     legend = TextLine(title="Group legend",
                       required=False)
 
--- a/src/pyams_form/templates/form.pt	Wed Sep 20 12:13:36 2017 +0200
+++ b/src/pyams_form/templates/form.pt	Thu Sep 21 14:29:32 2017 +0200
@@ -55,7 +55,7 @@
 					<tal:loop repeat="group view.groups">
 						<fieldset tal:define="legend group.legend"
 								  tal:omit-tag="not:legend"
-								  tal:attributes="class 'bordered' if group.bordered else None">
+								  tal:attributes="class (group.fieldset_class or '') + (' bordered' if group.bordered else '')">
 							<tal:if condition="group.checkbox_switch">
 								<legend data-ams-checker-value="selected"
 										tal:condition="legend"
--- a/src/pyams_form/templates/inner-form.pt	Wed Sep 20 12:13:36 2017 +0200
+++ b/src/pyams_form/templates/inner-form.pt	Thu Sep 21 14:29:32 2017 +0200
@@ -43,7 +43,7 @@
 			<tal:loop repeat="group view.groups">
 				<fieldset tal:define="legend group.legend"
 						  tal:omit-tag="not:legend"
-						  tal:attributes="class 'bordered' if group.bordered else None">
+						  tal:attributes="class (group.fieldset_class or '') + (' bordered' if group.bordered else '')">
 					<tal:if condition="group.checkbox_switch">
 						<legend data-ams-checker-value="selected"
 								tal:condition="legend"
--- a/src/pyams_form/templates/widget-form.pt	Wed Sep 20 12:13:36 2017 +0200
+++ b/src/pyams_form/templates/widget-form.pt	Thu Sep 21 14:29:32 2017 +0200
@@ -37,7 +37,7 @@
 					<tal:loop repeat="group view.groups">
 						<fieldset tal:define="legend group.legend"
 								  tal:omit-tag="not:legend"
-								  tal:attributes="class 'bordered' if group.bordered else None">
+								  tal:attributes="class (group.fieldset_class or '') + (' bordered' if group.bordered else '')">
 							<tal:if condition="group.checkbox_switch">
 								<legend data-ams-checker-value="selected"
 										tal:condition="legend"