You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Form Configuration with Schema Hints using Directives
10
+
# Form configuration with schema hints using directives
11
11
12
-
Dexterity uses the directives in [plone.autoform](http://pypi.python.org/pypi/plone.autoform) and [plone.supermodel](http://pypi.python.org/pypi/plone.supermodel) package to configure its [z3c.form](http://docs.zope.org/z3c.form)-based add and edit forms.
13
-
A directive annotates a schema with “form hints”, which are used to configure the form when it gets generated from the schema.
12
+
Dexterity uses the directives in [`plone.autoform`](https://pypi.org/project/plone.autoform/) and [`plone.supermodel`](https://pypi.org/project/plone.supermodel/) packages to configure its [`z3c.form`](https://z3cform.readthedocs.io/en/latest/)-based add and edit forms.
13
+
A directive annotates a schema with "form hints", which are used to configure the form when it gets generated from the schema.
14
14
15
-
The easiest way to apply form hints in Python code is to use the directives from [plone.autoform](http://pypi.python.org/pypi/plone.autoform) and [plone.supermodel](http://pypi.python.org/pypi/plone.supermodel).
16
-
For the directives to work, the schema must derive from *plone.supermodel.model.Schema*.
15
+
The easiest way to apply form hints in Python code is to use the directives from [`plone.autoform`](https://pypi.org/project/plone.autoform/) and `plone.supermodel`.
16
+
For the directives to work, the schema must derive from `plone.supermodel.model.Schema`.
17
17
18
18
Directives can be placed anywhere in the class body (annotations are made directly on the class).
19
-
By convention they are kept next to the fields they apply to.
19
+
By convention they are kept next to the fields to which they apply.
20
20
21
-
For example, here is a schema that omits a field:
21
+
For example, here is a schema that omits a field.
22
22
23
23
```python
24
24
from plone.autoform import directives
@@ -28,41 +28,41 @@ from zope import schema
28
28
29
29
classISampleSchema(model.Schema):
30
30
31
-
title = schema.TextLine(title='Title')
31
+
title = schema.TextLine(title="Title")
32
32
33
-
directives.omitted('additionalInfo')
33
+
directives.omitted("additionalInfo")
34
34
additionalInfo = schema.Bytes()
35
35
```
36
36
37
-
The form directives are taking parameters in the form of a list of field names,
38
-
or a set of field name/value pairs as keyword arguments.
37
+
The form directives take parameters in the form of a list of field names, or a set of field name/value pairs as keyword arguments.
39
38
Each directive can be used zero or more times.
40
39
41
-
There are two kinds of directives:
40
+
There are two kinds of directives.
42
41
43
-
-appearance related directives
44
-
-security related directives
42
+
- Appearance related directives
43
+
- Security related directives
45
44
46
-
## Appearance Related Directives
47
45
48
-
*plone.autoform.directives* provides these:
46
+
## Appearance related directives
47
+
48
+
`plone.autoform.directives` provides the following.
| widget | Specify an alternate widget for a field. Pass the field name as a key and a widget as the value. The widget can either be a z3c.form widget instance or a string giving the dotted name to one. |
51
+
| - | -|
52
+
| widget | Specify an alternate widget for a field. Pass the field name as a key and a widget as the value. The widget can either be a `z3c.form` widget instance or a string giving the dotted name to one. |
53
53
| omitted | Omit one or more fields from forms. Takes a sequence of field names as parameters. |
54
-
| mode | Set the widget mode for one or more fields. Pass the field name as a key and the string ‘input’, ‘display’ or ‘hidden’ as the value. |
55
-
| order_before | Specify that a given field should be rendered before another. Fields can only be ordered if they are in the same fieldset, otherwise order directive is ignored. Pass the field name as a key and name of the other field as a value. If the other field is in a supplementary schema (i.e. one from a behavior), its name will be e.g. `IOtherSchema.other_field_name`. If the other field is from the same schema, its name can be abbreviated by a leading dot e.g. `.other_field_name`. If the other field is is used without a prefix, its is looked up from the main schema e.g. `other_field_name`. Alternatively, pass the string “\*” to put a field first in the fieldsets form. |
56
-
| order_after | The inverse of order_before(), putting a field after another. It works almost similar to `order_before`, except passing “\*” will put the field at the end of the fieldsets form. |
54
+
| mode | Set the widget mode for one or more fields. Pass the field name as a key and the string `"input"`, `"display"`, or `"hidden"` as the value. |
55
+
| order_before | Specify that a given field should be rendered before another. Fields can only be ordered if they are in the same fieldset, otherwise order directive is ignored. Pass the field name as a key and name of the other field as a value. If the other field is in a supplementary schema such as from a behavior, then its name will be, for example `IOtherSchema.other_field_name`. If the other field is from the same schema, its name can be abbreviated by a leading dot, for example `.other_field_name`. If the other field is is used without a prefix, it is looked up from the main schema, for example `other_field_name`. Alternatively, pass the string `*` to put a field first in the form's fieldset. |
56
+
| order_after | The inverse of `order_before()`, putting a field after another. It works almost similar to `order_before`, except passing `*` will put the field at the end of the fieldsets form. |
57
57
58
-
*plone.supermodel.directives* provides these:
58
+
`plone.supermodel.directives` provides the following.
| fieldset | Creates a new (or reuses an existing) fieldset (rendered in Plone as a tab on the edit form). |
63
63
| primary | Designate a given field as the primary field in the schema. This is not used for form rendering, but is used for WebDAV marshaling of the content object. |
64
64
65
-
The code sample below illustrates each of these directives:
65
+
The code sample below illustrates each of these directives.
66
66
67
67
```python
68
68
from plone.autoform import directives
@@ -75,70 +75,71 @@ from zope import schema
75
75
76
76
classISampleSchema(model.Schema):
77
77
78
-
# A fieldset with id 'extra' and label 'Extra information' containing
79
-
# the 'footer' and 'dummy' fields. The label can be omitted if the
78
+
# A fieldset with id "extra" and label "Extra information" containing
79
+
# the "footer" and "dummy" fields. The label can be omitted if the
80
80
# fieldset has already been defined.
81
81
82
-
fieldset('extra',
83
-
label='Extra information',
84
-
fields=['footer', 'dummy']
82
+
fieldset("extra",
83
+
label="Extra information",
84
+
fields=["footer", "dummy"]
85
85
)
86
86
87
87
# Here a widget is specified as a dotted name.
88
88
# The body field is also designated as the primary field for this schema
| read_permission | Set the name (zcml-style) of a permission required to read the field’s value. Pass the field name as a key and the permission name as a string value. Among other things, this controls the field’s appearance in display forms. |
139
-
| write_permission | Set the name (zcml-style) of a permission required to write the field’s value. Pass the field name as a key and the permission name as a string value. Among other things, this controls the field’s appearance in add and edit forms. |
139
+
| read_permission | Set the name (ZCML-style) of a permission required to read the field's value. Pass the field name as a key and the permission name as a string value. Among other things, this controls the field's appearance in display forms. |
140
+
| write_permission | Set the name (ZCML-style) of a permission required to write the field's value. Pass the field name as a key and the permission name as a string value. Among other things, this controls the field's appearance in add and edit forms. |
140
141
141
-
The code sample below illustrates each of these directives:
142
+
The code sample below illustrates each of these directives.
142
143
143
144
```python
144
145
from plone.autoform import directives
@@ -147,13 +148,13 @@ from zope import schema
147
148
148
149
classISampleSchema(model.Schema):
149
150
150
-
# This field requires the 'cmf.ReviewPortalContent' permission
151
+
# This field requires the "cmf.ReviewPortalContent" permission
0 commit comments