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
Copy file name to clipboardExpand all lines: docs/backend/fields.md
+56-52Lines changed: 56 additions & 52 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,23 +13,24 @@ myst:
13
13
14
14
This chapter describes the standard schema fields for Plone forms and content types.
15
15
16
-
The following tables show the most common field types for use in {ref}`classic-ui-forms-label` and Dexterity {ref}`backend-content-types-label`.
17
-
See {ref}`schemas <backend-schemas-label>` for information about how fields compose a schema for a form or content type data model.
16
+
The following tables show the most common field types for use in {doc}`/classic-ui/forms` and Dexterity {doc}`/backend/content-types/index`.
17
+
See {doc}`schemas </backend/schemas>` for information about how fields compose a schema for a form or content type data model.
18
18
19
-
```{note}
20
-
In VS Code editor, you can install the [Plone Snippets](https://marketplace.visualstudio.com/items?itemName=Derico.plone-vs-snippets) extension. This will give you snippets for most fields, widgets and autoform directives in Python and XML based schemas.
19
+
```{tip}
20
+
In VS Code editor, you can install the [Plone Snippets](https://marketplace.visualstudio.com/items?itemName=Derico.plone-vs-snippets) extension.
21
+
This will give you snippets for most fields, widgets, and autoform directives in Python and XML based schemas.
21
22
```
22
23
23
24
## Field properties
24
25
25
-
Fields are initialized with properties passed in their constructors.
26
-
To avoid having to repeat the available properties for each field, we'll list them once here, grouped into the interfaces that describe them.
26
+
You can initialize fields by passing properties into their constructors.
27
+
To avoid repeating the available properties for each field, we'll list them once here, grouped into the interfaces that describe them.
27
28
You'll see those interfaces again in the tables below that describe the various field types.
28
29
Refer to the table below to see what properties a particular interface implies.
29
30
30
31
| Interface | Property | Type | Description |
31
32
| - | - | - | - |
32
-
| IField | title | int | The title of the field. Used in the widget. |
33
+
|`IField`|`title`| int | The title of the field. Used in the widget. |
33
34
||`description`| unicode | A description for the field. Used in the widget. |
34
35
||`required`| bool | Whether or not the field is required. Used for form validation. The default is `True`. |
35
36
||`readonly`| bool | Whether or not the field is read only. Default is `False`. |
@@ -38,54 +39,57 @@ Refer to the table below to see what properties a particular interface implies.
38
39
||`missing_value`|| A value that represents "this field is not set". Used by form validation. Defaults to `None`. For lists and tuples, it is sometimes useful to set this to an empty list or tuple. |
39
40
|`IMinMaxLen`|`min_length`| int | The minimum required length or minimum number of elements. Used for `string`, sequence, mapping, or `set` fields. Default is `0`. |
40
41
||`max_length `| int | The maximum allowed length or maximum number of elements. Used for `string`, sequence, mapping, or `set` fields. Default is `None` (no check). |
41
-
|`IMinMax`|`min`|| The minimum allowed value. Must be a valid value for the field, for example, an int field should be an integer. Default is `None` (no check). |
42
-
||`max`|| The maximum allowed value. Must be a valid value for the field, for example an int field should be an integer. Default is `None` (no check). |
43
-
|`ICollection`|`value_type`|| Another `Field` instance that describes the allowable values in a list, tuple, or other collection. Must be set for any collection field. One common usage is to set this to a `Choice` to model a multi-selection field with a {ref}`vocabulary <backend-vocabularies-label>`. |
42
+
|`IMinMax`|`min`|| The minimum allowed value. Must be a valid value for the field, for example, an `int` field should be an integer. Default is `None` (no check). |
43
+
||`max`|| The maximum allowed value. Must be a valid value for the field, for example an `int` field should be an integer. Default is `None` (no check). |
44
+
|`ICollection`|`value_type`|| Another `Field` instance that describes the allowable values in a list, tuple, or other collection. Must be set for any collection field. One common usage is to set this to a `Choice` to model a multi-selection field with a {doc}`vocabulary </backend/vocabularies>`. |
44
45
||`unique`| bool | Whether or not values in the collection must be unique. Usually not set directly. Use a `Set` or `Frozenset` to guarantee uniqueness in an efficient way. |
45
-
|`IDict`|`key_type`|| Another `Field` instance that describes the allowable keys in a dictionary. Similar to the `value_type` of a collection. Must be set. |
46
-
||`value_type`|| Another `Field` instance that describes the allowable values in a dictionary. Similar to the `value_type` of a collection. Must be set. |
46
+
|`IDict`|`key_type`|| Another `Field` instance that describes the allowable keys in a dictionary. Similar to the `value_type` of a collection. Must be a `Set`. |
47
+
||`value_type`|| Another `Field` instance that describes the allowable values in a dictionary. Similar to the `value_type` of a collection. Must be a `Set`. |
47
48
|`IObject`|`schema`|`Interface`| An interface that must be provided by any object stored in this field. |
48
49
|`IRichText`|`default_mime_type`| str | Default MIME type for the input text of a rich text field. Defaults to `text/html`. |
49
-
||`output_mime_type`| str | Default output MIME type for the transformed value of a rich text field. Defaults to `text/x-html-safe`. There must be a transformation chain in the `portal_transforms` tool that can transform from the input value to the `output` value for the output property of the `RichValue` object to contain a value. |
50
+
||`output_mime_type`| str | Default output MIME type for the transformed value of a rich text field. Defaults to `text/x-html-safe`. There must be a transformation chain in the `portal_transforms` tool that can transform from the input value to the output value for the `output` property of the `RichValue` object to contain a value. |
50
51
||`allowed_mime_types`| tuple | A list of allowed input MIME types. The default is `None`, in which case the site-wide settings from the {guilabel}`Markup` control panel will be used. |
51
52
52
53
See [IField interface](https://zopeschema.readthedocs.io/en/latest/api.html#zope.schema.interfaces.IField) and [field implementation](https://zopeschema.readthedocs.io/en/latest/api.html#field-implementations) in `zope.schema` documentation for details.
53
54
55
+
54
56
## Field types
55
57
56
58
The following tables describe the most commonly used field types, grouped by the module from which they can be imported.
57
59
58
60
61
+
(fields-in-zope-schema-label)=
62
+
59
63
### Fields in `zope.schema`
60
64
61
65
| Name | Type | Description | Properties |
62
66
| - | - | - | - |
63
-
| Choice |N/A| Used to model selection from a vocabulary, which must be supplied. Often used as the `value_type` of a selection field. The value type is the value of the terms in the vocabulary. | See {ref}`backend-vocabularies-label`. |
64
-
| Bytes | str | Used for binary data. | IField, IMinMaxLen |
| SourceText | unicode | A textfield intended to store source text, such as HTML or Python code. | IField, IMinMaxLen |
83
-
| Object | N/A | Stores a Python object that conforms to the interface given as the `schema`. There is no standard widget for this. | IField, IObject |
84
-
| URI | str | A URI (URL) string. | IField, MinMaxLen |
85
-
|Id| str | A unique identifier, either a URI or a dotted name. | IField, IMinMaxLen |
86
-
| DottedName | str | A dotted name string. | IField, IMinMaxLen |
| Decimal | Decimal | Stores a Python `Decimal`. Requires version 3.4 or later of [`zope.schema`](https://pypi.org/project/zope.schema/). Not available by default in Zope 2.10. | IField, IMinMax |
67
+
|`Choice`|n/a| Used to model selection from a vocabulary, which must be supplied. Often used as the `value_type` of a selection field. The value type is the value of the terms in the vocabulary. | See {doc}`/backend/vocabularies`. |
68
+
|`Bytes`| str | Used for binary data. |`IField`, `IMinMaxLen`|
69
+
|`ASCII`| str | ASCII text (multi-line). |`IField`, `IMinMaxLen`|
70
+
|`BytesLine`| str | A single line of binary data, in other words a `Bytes` with new lines disallowed. |`IField`, `IMinMaxLen`|
71
+
|`ASCIILine`| str | A single line of ASCII text. |`IField`, `IMinMaxLen`|
72
+
|`Text`| unicode | Unicode text (multi-line). Often used with a WYSIWYG widget, although the default is a text area. |`IField`, `IMinMaxLen`|
73
+
|`TextLine`| unicode | A single line of Unicode text. |`IField`, `IMinMaxLen`|
74
+
|`Bool`| bool |`True` or `False`. |`IField`|
75
+
|`Int`| int, long | An integer number. Both ints and longs are allowed. |`IField`, `IMinMax`|
76
+
|`Float`| float | A floating point number. |`IField`, `IMinMax`|
77
+
|`Tuple`| tuple | A tuple (non-mutable). |`IField`, `ICollection`, `IMinMaxLen`|
78
+
|`List`| list | A list. |`IField`, `ICollection`, `IMinMaxLen`|
79
+
|`Set`| set | A set. |`IField`, `ICollection`, `IMinMaxLen`|
80
+
|`Frozenset`| frozenset | A frozenset (non-mutable). |`IField`, `ICollection`, `IMinMaxLen`|
81
+
|`Password`| unicode | Stores a simple string, but implies a password widget. |`IField`, `IMinMaxLen`|
82
+
|`Dict`| dict | Stores a dictionary. Both `key_type` and `value_type` must be set to fields. |`IField`, `IMinMaxLen`, `IDict`|
83
+
|`Datetime`| datetime | Stores a Python `datetime` (not a Zope 2 `DateTime`). |`IField`, `IMinMax`|
84
+
|`Date`| date | Stores a Python`date`. |`IField`, `IMinMax`|
85
+
|`Timedelta`| timedelta | Stores a Python`timedelta`. |`IField`, `IMinMax`|
86
+
|`SourceText`| unicode | A textfield intended to store source text, such as HTML or Python code. |`IField`, `IMinMaxLen`|
87
+
|`Object`| N/A | Stores a Python object that conforms to the interface given as the `schema`. There is no standard widget for this. |`IField`, `IObject`|
88
+
|`URI`| str | A URI (URL) string. |`IField`, `MinMaxLen`|
89
+
|`Id`| str | A unique identifier, either a URI or a dotted name. |`IField`, `IMinMaxLen`|
90
+
|`DottedName`| str | A dotted name string. |`IField`, `IMinMaxLen`|
91
+
|`InterfaceField`| Interface | A Zope interface. |`IField`|
92
+
|`Decimal`| Decimal | Stores a Python `Decimal`. Requires version 3.4 or later of [`zope.schema`](https://pypi.org/project/zope.schema/). Not available by default in Zope 2.10. |`IField`, `IMinMax`|
89
93
90
94
91
95
### Fields in `plone.namedfile.field`
@@ -94,40 +98,40 @@ See [`plone.namedfile`](https://pypi.org/project/plone.namedfile/) and [plone.fo
94
98
95
99
| Name | Type | Description | Properties |
96
100
| - | - | - | - |
97
-
| NamedFile | NamedFile | A binary uploaded file. Normally used with the widget from `plone.formwidget.namedfile`. | IField |
98
-
| NamedImage | NamedImage | A binary uploaded image. Normally used with the widget from `plone.formwidget.namedfile`. | IField |
99
-
| NamedBlobFile | NamedBlobFile | A binary uploaded file stored as a ZODB blob. Requires the `blobs` extra to `plone.namedfile`. Otherwise identical to `NamedFile`. | IField |
100
-
| NamedBlobImage | NamedBlobImage | A binary uploaded image stored as a ZODB blob. Requires the `blobs` extra to `plone.namedfile`. Otherwise identical to `NamedImage`. | IField |
101
+
|`NamedFile`|`NamedFile`| A binary uploaded file. Normally used with the widget from `plone.formwidget.namedfile`. |`IField`|
102
+
|`NamedImage`|`NamedImage`| A binary uploaded image. Normally used with the widget from `plone.formwidget.namedfile`. |`IField`|
103
+
|`NamedBlobFile`|`NamedBlobFile`| A binary uploaded file stored as a ZODB blob. Requires the `blobs` extra to `plone.namedfile`. Otherwise identical to `NamedFile`. |`IField`|
104
+
|`NamedBlobImage`|`NamedBlobImage`| A binary uploaded image stored as a ZODB blob. Requires the `blobs` extra to `plone.namedfile`. Otherwise identical to `NamedImage`. |`IField`|
101
105
102
106
103
107
### Fields in `z3c.relationfield.schema`
104
108
105
109
See [`z3c.relationfield`](https://pypi.org/project/z3c.relationfield/) for more details.
| RichText | RichTextValue | Stores a `RichTextValue`, which encapsulates a raw text value, the source MIME type, and a cached copy of the raw text transformed to the default output MIME type. | IField, IRichText |
123
+
| - | - | - | - |
124
+
|`RichText`|`RichTextValue`| Stores a `RichTextValue`, which encapsulates a raw text value, the source MIME type, and a cached copy of the raw text transformed to the default output MIME type. |`IField`, `IRichText`|
121
125
122
126
123
127
### Fields in `plone.schema`
124
128
125
129
See {ref}`backend-ploneschema-label` for more details.
0 commit comments