Skip to content

Commit b9a5af9

Browse files
committed
show how to override the add form
1 parent 0a0f82b commit b9a5af9

File tree

1 file changed

+63
-11
lines changed

1 file changed

+63
-11
lines changed

docs/classic-ui/forms.md

Lines changed: 63 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ Fields, Widgets, Vocabularies aso are descripted in detail in there own chapter
1818

1919

2020
Plone uses the [z3c.form](http://pythonhosted.org/z3c.form) library to build its web-forms.
21-
The package responsible for integrating with Plone is [plone.z3cform](http://pypi.python.org/pypi/plone.z3cform).
21+
The package responsible for integrating with Plone is [plone.z3cform](http://http://github/plone//plone.z3cform).
2222

23-
To simplify the process of organizing a form and specifying its widgets and fields, Plone utilizes [plone.autoform](http://pypi.python.org/pypi/plone.autoform), in particular its `AutoExtensibleForm` base class.
23+
To simplify the process of organizing a form and specifying its widgets and fields, Plone utilizes [plone.autoform](http://github/plone/plone.autoform), in particular its `AutoExtensibleForm` base class.
2424
It is responsible for handling form hints and configuring z3c.form widgets and groups (fieldsets).
2525

2626
A form is a view that utilizes these libraries.
@@ -105,21 +105,32 @@ class MyForm(AutoExtensibleForm, form.EditForm):
105105
## Dexterity Add- and Edit forms
106106

107107
Dexterity content types are coming with default add and edit forms.
108-
You can build custom add and edit forms if you need.
108+
You can build custom add and edit forms to adjust there behavior.
109+
110+
The implementation of the default edit and add forms is in [plone.dexterity.browser.edit.py](https://github.com/plone/plone.dexterity/blob/master/plone/dexterity/browser/edit.py) and [plone.dexterity.browser.add.py](https://github.com/plone/plone.dexterity/blob/master/plone/dexterity/browser/add.py).
111+
112+
109113

110114

111115
```{todo}
112116
Describe Add/Edit forms here and how to customize them.
117+
Provide mutiple examples.
113118
```
114119

115120

116121
### Disable form tabbing
117122

118-
To disable the form tabbing, you have to override the form and provide a property enable_form_tabbing which is False.
123+
To disable the form tabbing, you have to override the edit and add forms and provide a property enable_form_tabbing which is False.
119124

120-
The Python code `custom_edit_form.py` should look like this:
125+
The Python code `custom_forms.py` should look like this:
121126

122127
```python
128+
from plone.dexterity.browser import add
129+
from plone.dexterity.browser import edit
130+
from zope.interface import implementer
131+
from zope.interface import Interface
132+
133+
123134
class ICustomEditForm(Interface):
124135
"""
125136
"""
@@ -130,9 +141,30 @@ class CustomEditForm(edit.DefaultEditForm):
130141
"""
131142
enable_form_tabbing = False
132143

144+
145+
class ICustomAddForm(Interface):
146+
"""
147+
"""
148+
149+
150+
@implementer(ICustomAddForm)
151+
class CustomAddForm(add.DefaultAddForm):
152+
""" Custom add form disabling form_tabbing
153+
"""
154+
enable_form_tabbing = False
155+
156+
157+
class ICustomAddView(Interface):
158+
""" """
159+
160+
161+
@implementer(ICustomAddView)
162+
class CustomAddView(add.DefaultAddView):
163+
form = CustomAddForm
164+
133165
```
134166

135-
to activate it, you have to override the registration of the edit form for your desired content types.
167+
to activate them, you have to override the registration of the forms for your desired content types.
136168
In your configure.zcml:
137169

138170
```xml
@@ -141,21 +173,41 @@ In your configure.zcml:
141173
xmlns:browser="http://namespaces.zope.org/browser"
142174
i18n_domain="example.contenttypes">
143175

144-
<!-- for TTW CT's -->
176+
<!-- Edit form -->
145177
<browser:page
146178
name="edit"
147-
for="plone.dexterity.interfaces.IDexterityContainer"
148-
class=".custom_edit_form.CustomEditForm"
179+
for="example.contenttypes.content.technical_facility.ITechnicalFacility"
180+
class=".custom_forms.CustomEditForm"
149181
permission="cmf.ModifyPortalContent"
150182
layer="example.contenttypes.interfaces.IExampleContenttypesLayer"
151183
/>
152184

185+
<!-- Edit form for TTW CT's -->
153186
<browser:page
154187
name="edit"
155-
for="example.contenttypes.content.technical_facility.ITechnicalFacility"
156-
class=".custom_edit_form.CustomEditForm"
188+
for="plone.dexterity.interfaces.IDexterityContainer"
189+
class=".custom_forms.CustomEditForm"
157190
permission="cmf.ModifyPortalContent"
158191
layer="example.contenttypes.interfaces.IExampleContenttypesLayer"
159192
/>
193+
194+
<!-- Add form -->
195+
<adapter
196+
factory=".custom_forms.CustomAddView"
197+
provides="zope.publisher.interfaces.browser.IBrowserPage"
198+
for="Products.CMFCore.interfaces.IFolderish
199+
example.contenttypes.interfaces.IExampleContenttypesLayer
200+
plone.dexterity.interfaces.IDexterityFTI"
201+
name="TechnicalFacility"
202+
/>
203+
204+
<class class=".custom_forms.CustomAddView">
205+
<require
206+
permission="cmf.AddPortalContent"
207+
interface="zope.publisher.interfaces.browser.IBrowserPage"
208+
/>
209+
</class>
210+
160211
</configure>
161212
```
213+

0 commit comments

Comments
 (0)