@@ -76,16 +76,16 @@ For example, you can change the widget for the `human` boolean field to use "yes
7676:emphasize-lines: 7
7777:linenos:
7878
79- from plone.supermodel import model
80- from plone.autoform import directives as form
81- from z3c.form.browser.radio import RadioFieldWidget
79+ from plone.supermodel import model
80+ from plone.autoform import directives as form
81+ from z3c.form.browser.radio import RadioFieldWidget
8282
83- class IMySchema(model.Schema):
83+ class IMySchema(model.Schema):
8484
85- form.widget("human", RadioFieldWidget)
86- human = schema.Bool(
87- title = "Are you human?",
88- )
85+ form.widget("human", RadioFieldWidget)
86+ human = schema.Bool(
87+ title = "Are you human?",
88+ )
8989```
9090
9191You can also pass widget parameters to control attributes of the widget.
@@ -95,29 +95,29 @@ For example, you can set a CSS class:
9595:emphasize-lines: 7
9696:linenos:
9797
98- from plone.supermodel import model
99- from plone.autoform import directives as form
100- from z3c.form.browser.radio import RadioWidget
98+ from plone.supermodel import model
99+ from plone.autoform import directives as form
100+ from z3c.form.browser.radio import RadioWidget
101101
102- class IMySchema(model.Schema):
102+ class IMySchema(model.Schema):
103103
104- form.widget("human", klass="annoying")
105- human = schema.Bool(
106- title = "Are you human?",
107- )
104+ form.widget("human", klass="annoying")
105+ human = schema.Bool(
106+ title = "Are you human?",
107+ )
108108```
109109
110110In supermodel XML, you can specify the widget using a ` <form:widget> ` tag, which can have its own elements specifying parameters:
111111
112112``` {code-block} xml
113113:emphasize-lines: 3,4,5
114114
115- <field name="human" type="zope.schema.TextLine">
116- <title>Are you human?</title>
117- <form:widget type="z3c.form.browser.radio.RadioWidget">
118- <klass>annoying</klass>
119- </form:widget>
120- </field>
115+ <field name="human" type="zope.schema.TextLine">
116+ <title>Are you human?</title>
117+ <form:widget type="z3c.form.browser.radio.RadioWidget">
118+ <klass>annoying</klass>
119+ </form:widget>
120+ </field>
121121```
122122
123123``` {note}
@@ -212,7 +212,6 @@ During the update method though, the groups have been initialized and have their
212212To access widgets in a group, you have to access the group in the update method:
213213
214214``` python
215-
216215from z3c.form import form
217216
218217
@@ -231,7 +230,6 @@ You can customize widget options in the `updateWidgets()` method.
231230Note that ` fieldset ` (which is a group) is a ` subform ` , and this method only affects the current ` fieldset ` .
232231
233232``` python
234-
235233from z3c.form import form
236234
237235
@@ -253,7 +251,6 @@ class MyForm(form.Form):
253251With ` plone.z3cform ` , you can reorder the field widgets by overriding the ` update() ` method of the form class.
254252
255253``` python
256-
257254from z3c.form import form
258255from z3c.form.interfaces import HIDDEN_MODE
259256from plone.z3cform.fieldsets.utils import move
@@ -275,7 +272,6 @@ class MyForm(form.Form):
275272You also can use ` plone.autoform ` directives, as in this example used for forms:
276273
277274``` python
278-
279275from plone.autoform import directives as form
280276from z3c.form.interfaces import IAddForm, IEditForm
281277
@@ -305,7 +301,6 @@ Sometimes you need to pre-load widget values to show when the form is requested.
305301The following example shows how to do that.
306302
307303``` python
308-
309304from z3c.form import field
310305from z3c.form import form
311306from z3c.form.browser.checkbox import CheckBoxFieldWidget
@@ -346,7 +341,6 @@ This will result in a checked option value of `02`.
346341The following example shows how you can conditionally require widgets.
347342
348343``` python
349-
350344class ReportForm (form .Form ):
351345 """ A form to output an HTML report from chosen parameters """
352346
@@ -365,14 +359,12 @@ To add CSS classes to a widget, you can use the method `addClass()`.
365359This is useful when you have JavaScript associated with your form:
366360
367361``` python
368-
369362widget.addClass(" myspecialwidgetclass" )
370363```
371364
372365You can also override the widget CSS class by changing the ` klass ` attribute for a given widget:
373366
374367``` python
375-
376368self .widgets[" my_widget" ].klass = " my-custom-css-class"
377369```
378370
@@ -496,12 +488,12 @@ You can also interact with your `form` class instance from the widget template:
496488You can set the template used by the widget with the ` <z3c:widgetTemplate> ` ZCML directive.
497489
498490``` xml
499- <z3c : widgetTemplate
500- mode =" display"
501- widget =" .interfaces.INamedFileWidget"
502- layer =" z3c.form.interfaces.IFormLayer"
503- template =" file_display.pt"
504- />
491+ <z3c : widgetTemplate
492+ mode =" display"
493+ widget =" .interfaces.INamedFileWidget"
494+ layer =" z3c.form.interfaces.IFormLayer"
495+ template =" file_display.pt"
496+ />
505497```
506498
507499
@@ -523,14 +515,13 @@ Then add the following code to `configure.zcml`.
523515Remember to fix the path of the template according to your own paths.
524516
525517``` xml
526- <browser : page
527- name =" ploneform-render-widget"
528- for =" .demo.IDemoWidget"
529- class =" plone.app.z3cform.templates.RenderWidget"
530- permission =" zope.Public"
531- template =" path/to/template/demo-widget.pt"
532- />
533-
518+ <browser : page
519+ name =" ploneform-render-widget"
520+ for =" .demo.IDemoWidget"
521+ class =" plone.app.z3cform.templates.RenderWidget"
522+ permission =" zope.Public"
523+ template =" path/to/template/demo-widget.pt"
524+ />
534525```
535526
536527Then create a new marker interface in Python code.
@@ -599,7 +590,6 @@ class IMyFormSchema(zope.interface.Interface):
599590 schema = IMinMax,
600591 required = False
601592 )
602-
603593```
604594
605595Then you set the ` my_combined_field ` widget template in ` updateWidgets() ` :
@@ -630,7 +620,6 @@ Paste the following code in this file.
630620The code renders both widgets, {guilabel}` min ` and {guilabel}` max ` , in a single row.
631621
632622``` html
633-
634623<div class =" min-max-widget"
635624 tal:define =" widget0 python:view.subform.widgets.values()[0];
636625 widget1 python:view.subform.widgets.values()[1];" >
@@ -647,36 +636,26 @@ The code renders both widgets, {guilabel}`min` and {guilabel}`max`, in a single
647636 </div >
648637
649638 <div class =" widget-left" tal:define =" widget widget0" >
650-
651639 <div tal:content =" structure widget/render" >
652640 <input type =" text" size =" 24" value =" " />
653641 </div >
654-
655-
656642 </div >
657643
658644 <div class =" widget-separator" >
659645 -
660646 </div >
661647
662648 <div class =" widget-right" tal:define =" widget widget1" >
663-
664649 <div class =" widget" tal:content =" structure widget/render" >
665650 <input type =" text" size =" 24" value =" " />
666651 </div >
667-
668652 </div >
669653
670-
671654 <div tal:condition =" widget0/error"
672655 tal:replace =" structure widget/error/render" >error</div >
673-
674656 <div class =" error" tal:condition =" widget1/error"
675657 tal:replace =" structure widget1/error/render" >error</div >
676-
677-
678658 <div style =" clear : both " ><!-- --> </div >
679-
680659 <input name =" field-empty-marker" type =" hidden" value =" 1"
681660 tal:attributes =" name string:${view/name}-empty-marker" />
682661
0 commit comments