payload 1.0.27 → 1.0.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +36 -4
- package/dist/admin/components/elements/Status/index.js +1 -1
- package/dist/admin/components/elements/ViewDescription/types.d.ts +1 -1
- package/dist/admin/components/elements/WhereBuilder/index.js +3 -1
- package/dist/admin/components/forms/field-types/Array/index.d.ts +3 -2
- package/dist/admin/components/forms/field-types/Array/index.js +201 -6
- package/dist/admin/components/forms/field-types/Blocks/index.d.ts +3 -2
- package/dist/admin/components/forms/field-types/Blocks/index.js +213 -6
- package/dist/admin/components/forms/field-types/Collapsible/index.js +2 -2
- package/dist/admin/components/forms/field-types/Row/index.js +2 -2
- package/dist/admin/components/forms/field-types/Tabs/index.js +2 -2
- package/dist/admin/components/forms/field-types/getFieldPath.d.ts +2 -0
- package/dist/admin/components/forms/field-types/getFieldPath.js +6 -0
- package/dist/admin/components/forms/field-types/index.d.ts +23 -23
- package/dist/admin/components/utilities/RenderCustomComponent/types.d.ts +2 -2
- package/dist/admin/components/views/collections/List/Cell/field-types/Relationship/index.js +1 -1
- package/dist/auth/operations/local/forgotPassword.js +3 -6
- package/dist/auth/operations/local/login.js +6 -9
- package/dist/auth/operations/local/resetPassword.js +4 -7
- package/dist/auth/operations/local/unlock.js +4 -7
- package/dist/collections/buildSchema.js +2 -1
- package/dist/collections/config/types.d.ts +2 -2
- package/dist/collections/dataloader.js +16 -8
- package/dist/collections/operations/local/create.d.ts +2 -2
- package/dist/collections/operations/local/create.js +11 -13
- package/dist/collections/operations/local/find.js +6 -10
- package/dist/collections/operations/local/findByID.js +6 -10
- package/dist/collections/operations/local/findVersionByID.js +6 -9
- package/dist/config/types.d.ts +13 -13
- package/dist/fields/config/sanitize.js +3 -3
- package/dist/fields/config/schema.js +3 -3
- package/dist/fields/config/types.d.ts +9 -9
- package/dist/fields/validations.js +43 -1
- package/dist/globals/config/types.d.ts +1 -1
- package/dist/mongoose/buildSchema.d.ts +1 -0
- package/dist/mongoose/buildSchema.js +3 -3
- package/dist/utilities/getIDType.d.ts +2 -0
- package/dist/utilities/getIDType.js +11 -0
- package/dist/utilities/isValidID.d.ts +1 -0
- package/dist/utilities/isValidID.js +16 -0
- package/docs/access-control/collections.mdx +21 -12
- package/docs/access-control/fields.mdx +5 -3
- package/docs/access-control/globals.mdx +8 -4
- package/docs/access-control/overview.mdx +1 -1
- package/docs/admin/components.mdx +29 -25
- package/docs/admin/customizing-css.mdx +2 -2
- package/docs/admin/overview.mdx +2 -2
- package/docs/admin/webpack.mdx +8 -7
- package/docs/authentication/config.mdx +14 -9
- package/docs/authentication/operations.mdx +22 -22
- package/docs/authentication/overview.mdx +8 -6
- package/docs/authentication/using-middleware.mdx +1 -1
- package/docs/configuration/collections.mdx +11 -7
- package/docs/configuration/globals.mdx +9 -5
- package/docs/configuration/localization.mdx +33 -31
- package/docs/configuration/overview.mdx +4 -7
- package/docs/email/overview.mdx +11 -7
- package/docs/fields/array.mdx +6 -5
- package/docs/fields/blocks.mdx +6 -4
- package/docs/fields/checkbox.mdx +6 -5
- package/docs/fields/code.mdx +6 -5
- package/docs/fields/collapsible.mdx +6 -5
- package/docs/fields/date.mdx +6 -5
- package/docs/fields/email.mdx +6 -5
- package/docs/fields/group.mdx +6 -5
- package/docs/fields/number.mdx +6 -5
- package/docs/fields/overview.mdx +40 -38
- package/docs/fields/point.mdx +6 -4
- package/docs/fields/radio.mdx +5 -3
- package/docs/fields/relationship.mdx +21 -21
- package/docs/fields/rich-text.mdx +9 -7
- package/docs/fields/row.mdx +5 -3
- package/docs/fields/select.mdx +4 -3
- package/docs/fields/tabs.mdx +5 -3
- package/docs/fields/text.mdx +5 -3
- package/docs/fields/textarea.mdx +5 -3
- package/docs/fields/ui.mdx +5 -3
- package/docs/fields/upload.mdx +5 -3
- package/docs/getting-started/concepts.mdx +1 -1
- package/docs/graphql/extending.mdx +1 -1
- package/docs/graphql/overview.mdx +8 -4
- package/docs/hooks/collections.mdx +62 -36
- package/docs/hooks/fields.mdx +5 -3
- package/docs/hooks/globals.mdx +25 -17
- package/docs/local-api/overview.mdx +27 -4
- package/docs/plugins/overview.mdx +3 -4
- package/docs/production/deployment.mdx +1 -1
- package/docs/queries/overview.mdx +4 -2
- package/docs/queries/pagination.mdx +1 -1
- package/docs/rest-api/overview.mdx +4 -2
- package/docs/upload/overview.mdx +35 -29
- package/docs/versions/autosave.mdx +4 -2
- package/docs/versions/drafts.mdx +8 -4
- package/docs/versions/overview.mdx +1 -1
- package/package.json +1 -1
- package/types.d.ts +21 -0
- package/dist/admin/components/forms/field-types/Array/Array.d.ts +0 -5
- package/dist/admin/components/forms/field-types/Array/Array.js +0 -201
- package/dist/admin/components/forms/field-types/Blocks/Blocks.d.ts +0 -5
- package/dist/admin/components/forms/field-types/Blocks/Blocks.js +0 -213
|
@@ -14,21 +14,23 @@ Add the `localization` property to your Payload config to enable localization pr
|
|
|
14
14
|
|
|
15
15
|
**Example Payload config set up for localization:**
|
|
16
16
|
|
|
17
|
-
```
|
|
18
|
-
{
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
17
|
+
```ts
|
|
18
|
+
import { buildConfig } from 'payload/config'
|
|
19
|
+
|
|
20
|
+
export default buildConfig({
|
|
21
|
+
collections: [
|
|
22
|
+
// collections go here
|
|
23
|
+
],
|
|
24
|
+
localization: {
|
|
25
|
+
locales: [
|
|
26
|
+
'en',
|
|
27
|
+
'es',
|
|
28
|
+
'de',
|
|
29
|
+
],
|
|
30
|
+
defaultLocale: 'en',
|
|
31
|
+
fallback: true,
|
|
32
|
+
},
|
|
33
|
+
});
|
|
32
34
|
```
|
|
33
35
|
|
|
34
36
|
**Here is a brief explanation of each of the options available within the `localization` property:**
|
|
@@ -53,11 +55,11 @@ Payload localization works on a **field** level—not a document level. In addit
|
|
|
53
55
|
|
|
54
56
|
```js
|
|
55
57
|
{
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
name: 'title',
|
|
59
|
+
type: 'text',
|
|
60
|
+
// highlight-start
|
|
61
|
+
localized: true,
|
|
62
|
+
// highlight-end
|
|
61
63
|
}
|
|
62
64
|
```
|
|
63
65
|
|
|
@@ -66,8 +68,8 @@ With the above configuration, the `title` field will now be saved in the databas
|
|
|
66
68
|
All field types with a `name` property support the `localized` property—even the more complex field types like `array`s and `block`s.
|
|
67
69
|
|
|
68
70
|
<Banner>
|
|
69
|
-
|
|
70
|
-
|
|
71
|
+
<strong>Note:</strong><br/>
|
|
72
|
+
Enabling localization for field types that support nested fields will automatically create localized "sets" of all fields contained within the field. For example, if you have a page layout using a blocks field type, you have the choice of either localizing the full layout, by enabling localization on the top-level blocks field, or only certain fields within the layout.
|
|
71
73
|
</Banner>
|
|
72
74
|
|
|
73
75
|
### Retrieving localized docs
|
|
@@ -104,16 +106,16 @@ The `fallbackLocale` arg will accept valid locales as well as `none` to disable
|
|
|
104
106
|
|
|
105
107
|
```graphql
|
|
106
108
|
query {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
109
|
+
Posts(locale: de, fallbackLocale: none) {
|
|
110
|
+
docs {
|
|
111
|
+
title
|
|
112
|
+
}
|
|
113
|
+
}
|
|
112
114
|
}
|
|
113
115
|
```
|
|
114
116
|
|
|
115
117
|
<Banner>
|
|
116
|
-
|
|
118
|
+
In GraphQL, specifying the locale at the top level of a query will automatically apply it throughout all nested relationship fields. You can override this behavior by re-specifying locale arguments in nested related document queries.
|
|
117
119
|
</Banner>
|
|
118
120
|
|
|
119
121
|
##### Local API
|
|
@@ -124,9 +126,9 @@ You can specify `locale` as well as `fallbackLocale` within the Local API as wel
|
|
|
124
126
|
|
|
125
127
|
```js
|
|
126
128
|
const posts = await payload.find({
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
129
|
+
collection: 'posts',
|
|
130
|
+
locale: 'es',
|
|
131
|
+
fallbackLocale: false,
|
|
130
132
|
})
|
|
131
133
|
```
|
|
132
134
|
|
|
@@ -43,10 +43,10 @@ Payload is a *config-based*, code-first CMS and application framework. The Paylo
|
|
|
43
43
|
|
|
44
44
|
#### Simple example
|
|
45
45
|
|
|
46
|
-
```
|
|
46
|
+
```ts
|
|
47
47
|
import { buildConfig } from 'payload/config';
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
export default buildConfig({
|
|
50
50
|
collections: [
|
|
51
51
|
{
|
|
52
52
|
slug: 'pages',
|
|
@@ -83,9 +83,6 @@ const config = buildConfig({
|
|
|
83
83
|
}
|
|
84
84
|
]
|
|
85
85
|
});
|
|
86
|
-
|
|
87
|
-
export default config;
|
|
88
|
-
|
|
89
86
|
```
|
|
90
87
|
|
|
91
88
|
#### Full example config
|
|
@@ -174,14 +171,14 @@ Then, you could import this file into both your Payload config and your server,
|
|
|
174
171
|
|
|
175
172
|
You can import config types as follows:
|
|
176
173
|
|
|
177
|
-
```
|
|
174
|
+
```ts
|
|
178
175
|
import { Config } from 'payload/config';
|
|
179
176
|
|
|
180
177
|
// This is the type used for an incoming Payload config.
|
|
181
178
|
// Only the bare minimum properties are marked as required.
|
|
182
179
|
```
|
|
183
180
|
|
|
184
|
-
```
|
|
181
|
+
```ts
|
|
185
182
|
import { SanitizedConfig } from 'payload/config';
|
|
186
183
|
|
|
187
184
|
// This is the type used after an incoming Payload config is fully sanitized.
|
package/docs/email/overview.mdx
CHANGED
|
@@ -40,7 +40,7 @@ The following options are configurable in the `email` property object as part of
|
|
|
40
40
|
Simple Mail Transfer Protocol, also known as SMTP can be passed in using the `transportOptions` object on the `email` options.
|
|
41
41
|
|
|
42
42
|
**Example email part using SMTP:**
|
|
43
|
-
```
|
|
43
|
+
```ts
|
|
44
44
|
payload.init({
|
|
45
45
|
email: {
|
|
46
46
|
transportOptions: {
|
|
@@ -60,6 +60,7 @@ payload.init({
|
|
|
60
60
|
fromAddress: 'hello@example.com'
|
|
61
61
|
}
|
|
62
62
|
// ...
|
|
63
|
+
})
|
|
63
64
|
```
|
|
64
65
|
|
|
65
66
|
<Banner type="warning">
|
|
@@ -70,9 +71,9 @@ payload.init({
|
|
|
70
71
|
|
|
71
72
|
Many third party mail providers are available and offer benefits beyond basic SMTP. As an example your payload init could look this if you wanted to use SendGrid.com though the same approach would work for any other [NodeMailer transports](https://nodemailer.com/transports/) shown here or provided by another third party.
|
|
72
73
|
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
```ts
|
|
75
|
+
import payload from 'payload'
|
|
76
|
+
import nodemailerSendgrid from 'nodemailer-sendgrid'
|
|
76
77
|
|
|
77
78
|
const sendGridAPIKey = process.env.SENDGRID_API_KEY;
|
|
78
79
|
|
|
@@ -92,7 +93,10 @@ payload.init({
|
|
|
92
93
|
### Use a custom NodeMailer transport
|
|
93
94
|
To take full control of the mail transport you may wish to use `nodemailer.createTransport()` on your server and provide it to Payload init.
|
|
94
95
|
|
|
95
|
-
```
|
|
96
|
+
```ts
|
|
97
|
+
import payload from 'payload'
|
|
98
|
+
import nodemailer from 'nodemailer'
|
|
99
|
+
|
|
96
100
|
const payload = require('payload');
|
|
97
101
|
const nodemailer = require('nodemailer');
|
|
98
102
|
|
|
@@ -112,7 +116,7 @@ payload.init({
|
|
|
112
116
|
transport
|
|
113
117
|
},
|
|
114
118
|
// ...
|
|
115
|
-
}
|
|
119
|
+
});
|
|
116
120
|
```
|
|
117
121
|
|
|
118
122
|
### Sending Mail
|
|
@@ -123,7 +127,7 @@ By default, Payload uses a mock implementation that only sends mail to the [ethe
|
|
|
123
127
|
|
|
124
128
|
To see ethereal credentials, add `logMockCredentials: true` to the email options. This will cause them to be logged to console on startup.
|
|
125
129
|
|
|
126
|
-
```
|
|
130
|
+
```ts
|
|
127
131
|
payload.init({
|
|
128
132
|
email: {
|
|
129
133
|
fromName: 'Admin',
|
package/docs/fields/array.mdx
CHANGED
|
@@ -41,9 +41,11 @@ keywords: array, fields, config, configuration, documentation, Content Managemen
|
|
|
41
41
|
|
|
42
42
|
### Example
|
|
43
43
|
|
|
44
|
-
`collections/ExampleCollection.
|
|
45
|
-
```
|
|
46
|
-
{
|
|
44
|
+
`collections/ExampleCollection.ts`
|
|
45
|
+
```ts
|
|
46
|
+
import { CollectionConfig } from 'payload/types';
|
|
47
|
+
|
|
48
|
+
const ExampleCollection: CollectionConfig = {
|
|
47
49
|
slug: 'example-collection',
|
|
48
50
|
fields: [
|
|
49
51
|
{
|
|
@@ -70,6 +72,5 @@ keywords: array, fields, config, configuration, documentation, Content Managemen
|
|
|
70
72
|
]
|
|
71
73
|
}
|
|
72
74
|
]
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
+
};
|
|
75
76
|
```
|
package/docs/fields/blocks.mdx
CHANGED
|
@@ -72,8 +72,10 @@ The Admin panel provides each block with a `blockName` field which optionally al
|
|
|
72
72
|
### Example
|
|
73
73
|
|
|
74
74
|
`collections/ExampleCollection.js`
|
|
75
|
-
```
|
|
76
|
-
|
|
75
|
+
```ts
|
|
76
|
+
import { Block, CollectionConfig } from 'payload/types';
|
|
77
|
+
|
|
78
|
+
const QuoteBlock: Block = {
|
|
77
79
|
slug: 'Quote', // required
|
|
78
80
|
imageURL: 'https://google.com/path/to/image.jpg',
|
|
79
81
|
imageAltText: 'A nice thumbnail image to show what this block looks like',
|
|
@@ -90,7 +92,7 @@ const QuoteBlock = {
|
|
|
90
92
|
]
|
|
91
93
|
};
|
|
92
94
|
|
|
93
|
-
const ExampleCollection = {
|
|
95
|
+
const ExampleCollection: CollectionConfig = {
|
|
94
96
|
slug: 'example-collection',
|
|
95
97
|
fields: [
|
|
96
98
|
{
|
|
@@ -111,7 +113,7 @@ const ExampleCollection = {
|
|
|
111
113
|
|
|
112
114
|
As you build your own Block configs, you might want to store them in separate files but retain typing accordingly. To do so, you can import and use Payload's `Block` type:
|
|
113
115
|
|
|
114
|
-
```
|
|
116
|
+
```ts
|
|
115
117
|
import type { Block } from 'payload/types';
|
|
116
118
|
|
|
117
119
|
```
|
package/docs/fields/checkbox.mdx
CHANGED
|
@@ -31,9 +31,11 @@ keywords: checkbox, fields, config, configuration, documentation, Content Manage
|
|
|
31
31
|
|
|
32
32
|
### Example
|
|
33
33
|
|
|
34
|
-
`collections/ExampleCollection.
|
|
35
|
-
```
|
|
36
|
-
{
|
|
34
|
+
`collections/ExampleCollection.ts`
|
|
35
|
+
```ts
|
|
36
|
+
import { CollectionConfig } from 'payload/types';
|
|
37
|
+
|
|
38
|
+
const ExampleCollection: CollectionConfig = {
|
|
37
39
|
slug: 'example-collection',
|
|
38
40
|
fields: [
|
|
39
41
|
{
|
|
@@ -43,6 +45,5 @@ keywords: checkbox, fields, config, configuration, documentation, Content Manage
|
|
|
43
45
|
defaultValue: false,
|
|
44
46
|
}
|
|
45
47
|
]
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
+
};
|
|
48
49
|
```
|
package/docs/fields/code.mdx
CHANGED
|
@@ -55,9 +55,11 @@ The following `prismjs` plugins are imported, enabling the `language` property t
|
|
|
55
55
|
|
|
56
56
|
### Example
|
|
57
57
|
|
|
58
|
-
`collections/ExampleCollection.
|
|
59
|
-
```
|
|
60
|
-
{
|
|
58
|
+
`collections/ExampleCollection.ts
|
|
59
|
+
```ts
|
|
60
|
+
import { CollectionConfig } from 'payload/types';
|
|
61
|
+
|
|
62
|
+
const ExampleCollection: CollectionConfig = {
|
|
61
63
|
slug: 'example-collection',
|
|
62
64
|
fields: [
|
|
63
65
|
{
|
|
@@ -69,6 +71,5 @@ The following `prismjs` plugins are imported, enabling the `language` property t
|
|
|
69
71
|
}
|
|
70
72
|
}
|
|
71
73
|
]
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
+
};
|
|
74
75
|
```
|
|
@@ -22,9 +22,11 @@ keywords: row, fields, config, configuration, documentation, Content Management
|
|
|
22
22
|
|
|
23
23
|
### Example
|
|
24
24
|
|
|
25
|
-
`collections/ExampleCollection.
|
|
26
|
-
```
|
|
27
|
-
{
|
|
25
|
+
`collections/ExampleCollection.ts`
|
|
26
|
+
```ts
|
|
27
|
+
import { CollectionConfig } from 'payload/types';
|
|
28
|
+
|
|
29
|
+
const ExampleCollection: CollectionConfig = {
|
|
28
30
|
slug: 'example-collection',
|
|
29
31
|
fields: [
|
|
30
32
|
{
|
|
@@ -39,6 +41,5 @@ keywords: row, fields, config, configuration, documentation, Content Management
|
|
|
39
41
|
],
|
|
40
42
|
}
|
|
41
43
|
]
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
+
};
|
|
44
45
|
```
|
package/docs/fields/date.mdx
CHANGED
|
@@ -55,10 +55,12 @@ Common use cases for customizing the `date` property are to restrict your field
|
|
|
55
55
|
|
|
56
56
|
### Example
|
|
57
57
|
|
|
58
|
-
`collections/ExampleCollection.
|
|
58
|
+
`collections/ExampleCollection.ts`
|
|
59
59
|
|
|
60
|
-
```
|
|
61
|
-
{
|
|
60
|
+
```ts
|
|
61
|
+
import { CollectionConfig } from 'payload/types';
|
|
62
|
+
|
|
63
|
+
const ExampleCollection: CollectionConfig = {
|
|
62
64
|
slug: 'example-collection',
|
|
63
65
|
fields: [
|
|
64
66
|
{
|
|
@@ -74,6 +76,5 @@ Common use cases for customizing the `date` property are to restrict your field
|
|
|
74
76
|
}
|
|
75
77
|
}
|
|
76
78
|
]
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
+
};
|
|
79
80
|
```
|
package/docs/fields/email.mdx
CHANGED
|
@@ -44,9 +44,11 @@ Set this property to a string that will be used for browser autocomplete.
|
|
|
44
44
|
|
|
45
45
|
### Example
|
|
46
46
|
|
|
47
|
-
`collections/ExampleCollection.
|
|
48
|
-
```
|
|
49
|
-
{
|
|
47
|
+
`collections/ExampleCollection.ts`
|
|
48
|
+
```ts
|
|
49
|
+
import { CollectionConfig } from 'payload/types';
|
|
50
|
+
|
|
51
|
+
const ExampleCollection: CollectionConfig = {
|
|
50
52
|
slug: 'example-collection',
|
|
51
53
|
fields: [
|
|
52
54
|
{
|
|
@@ -56,6 +58,5 @@ Set this property to a string that will be used for browser autocomplete.
|
|
|
56
58
|
required: true,
|
|
57
59
|
}
|
|
58
60
|
]
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
+
};
|
|
61
62
|
```
|
package/docs/fields/group.mdx
CHANGED
|
@@ -39,9 +39,11 @@ Set this property to `true` to hide this field's gutter within the admin panel.
|
|
|
39
39
|
|
|
40
40
|
### Example
|
|
41
41
|
|
|
42
|
-
`collections/ExampleCollection.
|
|
43
|
-
```
|
|
44
|
-
{
|
|
42
|
+
`collections/ExampleCollection.ts`
|
|
43
|
+
```ts
|
|
44
|
+
import { CollectionConfig } from 'payload/types';
|
|
45
|
+
|
|
46
|
+
const ExampleCollection: CollectionConfig = {
|
|
45
47
|
slug: 'example-collection',
|
|
46
48
|
fields: [
|
|
47
49
|
{
|
|
@@ -65,6 +67,5 @@ Set this property to `true` to hide this field's gutter within the admin panel.
|
|
|
65
67
|
],
|
|
66
68
|
}
|
|
67
69
|
]
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
+
};
|
|
70
71
|
```
|
package/docs/fields/number.mdx
CHANGED
|
@@ -50,9 +50,11 @@ Set this property to a string that will be used for browser autocomplete.
|
|
|
50
50
|
|
|
51
51
|
### Example
|
|
52
52
|
|
|
53
|
-
`collections/ExampleCollection.
|
|
54
|
-
```
|
|
55
|
-
{
|
|
53
|
+
`collections/ExampleCollection.ts`
|
|
54
|
+
```ts
|
|
55
|
+
import { CollectionConfig } from 'payload/types';
|
|
56
|
+
|
|
57
|
+
const ExampleCollection: CollectionConfig = {
|
|
56
58
|
slug: 'example-collection',
|
|
57
59
|
fields: [
|
|
58
60
|
{
|
|
@@ -64,6 +66,5 @@ Set this property to a string that will be used for browser autocomplete.
|
|
|
64
66
|
}
|
|
65
67
|
}
|
|
66
68
|
]
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
+
};
|
|
69
70
|
```
|
package/docs/fields/overview.mdx
CHANGED
|
@@ -16,8 +16,10 @@ Fields are defined as an array on Collections and Globals via the `fields` key.
|
|
|
16
16
|
The required `type` property on a field determines what values it can accept, how it is presented in the API, and how the field will be rendered in the admin interface.
|
|
17
17
|
|
|
18
18
|
**Simple collection with two fields:**
|
|
19
|
-
```
|
|
20
|
-
|
|
19
|
+
```ts
|
|
20
|
+
import { CollectionConfig } from 'payload/types';
|
|
21
|
+
|
|
22
|
+
const Page: CollectionConfig = {
|
|
21
23
|
slug: 'pages',
|
|
22
24
|
fields: [
|
|
23
25
|
{
|
|
@@ -29,7 +31,7 @@ const Pages = {
|
|
|
29
31
|
type: 'checkbox', // highlight-line
|
|
30
32
|
},
|
|
31
33
|
],
|
|
32
|
-
}
|
|
34
|
+
};
|
|
33
35
|
```
|
|
34
36
|
|
|
35
37
|
### Field types
|
|
@@ -80,8 +82,10 @@ There are two arguments available to custom validation functions.
|
|
|
80
82
|
| `payload` | If the `validate` function is being executed on the server, Payload will be exposed for easily running local operations. |
|
|
81
83
|
|
|
82
84
|
Example:
|
|
83
|
-
```
|
|
84
|
-
{
|
|
85
|
+
```ts
|
|
86
|
+
import { CollectionConfig } from 'payload/types';
|
|
87
|
+
|
|
88
|
+
const Orders: CollectionConfig = {
|
|
85
89
|
slug: 'orders',
|
|
86
90
|
fields: [
|
|
87
91
|
{
|
|
@@ -101,27 +105,27 @@ Example:
|
|
|
101
105
|
},
|
|
102
106
|
},
|
|
103
107
|
],
|
|
104
|
-
}
|
|
108
|
+
};
|
|
105
109
|
```
|
|
106
110
|
|
|
107
111
|
When supplying a field `validate` function, Payload will use yours in place of the default. To make use of the default field validation in your custom logic you can import, call and return the result as needed.
|
|
108
112
|
|
|
109
113
|
For example:
|
|
110
|
-
```
|
|
114
|
+
```ts
|
|
111
115
|
import { text } from 'payload/fields/validations';
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
116
|
+
|
|
117
|
+
const field: Field = {
|
|
118
|
+
name: 'notBad',
|
|
119
|
+
type: 'text',
|
|
120
|
+
validate: (val, args) => {
|
|
121
|
+
if (val === 'bad') {
|
|
122
|
+
return 'This cannot be "bad"';
|
|
123
|
+
}
|
|
124
|
+
// highlight-start
|
|
125
|
+
return text(val, args);
|
|
126
|
+
// highlight-end
|
|
127
|
+
},
|
|
128
|
+
};
|
|
125
129
|
```
|
|
126
130
|
|
|
127
131
|
### Customizable ID
|
|
@@ -131,7 +135,7 @@ Users are then required to provide a custom ID value when creating a record thro
|
|
|
131
135
|
Valid ID types are `number` and `text`.
|
|
132
136
|
|
|
133
137
|
Example:
|
|
134
|
-
```
|
|
138
|
+
```ts
|
|
135
139
|
{
|
|
136
140
|
fields: [
|
|
137
141
|
{
|
|
@@ -174,7 +178,7 @@ The `condition` function should return a boolean that will control if the field
|
|
|
174
178
|
|
|
175
179
|
**Example:**
|
|
176
180
|
|
|
177
|
-
```
|
|
181
|
+
```ts
|
|
178
182
|
{
|
|
179
183
|
fields: [
|
|
180
184
|
{
|
|
@@ -212,21 +216,21 @@ Functions are called with an optional argument object containing:
|
|
|
212
216
|
|
|
213
217
|
Here is an example of a defaultValue function that uses both:
|
|
214
218
|
|
|
215
|
-
```
|
|
219
|
+
```ts
|
|
216
220
|
const translation: {
|
|
217
|
-
|
|
218
|
-
|
|
221
|
+
en: 'Written by',
|
|
222
|
+
es: 'Escrito por',
|
|
219
223
|
};
|
|
220
224
|
|
|
221
225
|
const field = {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
226
|
+
name: 'attribution',
|
|
227
|
+
type: 'text',
|
|
228
|
+
admin: {
|
|
229
|
+
// highlight-start
|
|
230
|
+
defaultValue: ({ user, locale }) => (`${translation[locale]} ${user.name}`)
|
|
231
|
+
// highlight-end
|
|
232
|
+
}
|
|
233
|
+
};
|
|
230
234
|
```
|
|
231
235
|
|
|
232
236
|
<Banner type="success">
|
|
@@ -244,7 +248,7 @@ As shown above, you can simply provide a string that will show by the field, but
|
|
|
244
248
|
|
|
245
249
|
**Function Example:**
|
|
246
250
|
|
|
247
|
-
```
|
|
251
|
+
```ts
|
|
248
252
|
{
|
|
249
253
|
fields: [
|
|
250
254
|
{
|
|
@@ -262,7 +266,7 @@ As shown above, you can simply provide a string that will show by the field, but
|
|
|
262
266
|
This example will display the number of characters allowed as the user types.
|
|
263
267
|
|
|
264
268
|
**Component Example:**
|
|
265
|
-
```
|
|
269
|
+
```ts
|
|
266
270
|
{
|
|
267
271
|
fields: [
|
|
268
272
|
{
|
|
@@ -289,10 +293,8 @@ This component will count the number of characters entered.
|
|
|
289
293
|
|
|
290
294
|
You can import the internal Payload `Field` type as well as other common field types as follows:
|
|
291
295
|
|
|
292
|
-
```
|
|
296
|
+
```ts
|
|
293
297
|
import type {
|
|
294
298
|
Field,
|
|
295
|
-
Validate,
|
|
296
|
-
Condition,
|
|
297
299
|
} from 'payload/types';
|
|
298
300
|
```
|
package/docs/fields/point.mdx
CHANGED
|
@@ -35,9 +35,11 @@ The data structure in the database matches the GeoJSON structure to represent po
|
|
|
35
35
|
|
|
36
36
|
### Example
|
|
37
37
|
|
|
38
|
-
`collections/ExampleCollection.
|
|
39
|
-
```
|
|
40
|
-
{
|
|
38
|
+
`collections/ExampleCollection.ts`
|
|
39
|
+
```ts
|
|
40
|
+
import { CollectionConfig } from 'payload/types';
|
|
41
|
+
|
|
42
|
+
const ExampleCollection: CollectionConfig = {
|
|
41
43
|
slug: 'example-collection',
|
|
42
44
|
fields: [
|
|
43
45
|
{
|
|
@@ -46,7 +48,7 @@ The data structure in the database matches the GeoJSON structure to represent po
|
|
|
46
48
|
label: 'Location',
|
|
47
49
|
},
|
|
48
50
|
]
|
|
49
|
-
}
|
|
51
|
+
};
|
|
50
52
|
```
|
|
51
53
|
|
|
52
54
|
### Querying
|
package/docs/fields/radio.mdx
CHANGED
|
@@ -45,9 +45,11 @@ The `layout` property allows for the radio group to be styled as a horizonally o
|
|
|
45
45
|
|
|
46
46
|
### Example
|
|
47
47
|
|
|
48
|
-
`collections/ExampleCollection.
|
|
49
|
-
```
|
|
50
|
-
{
|
|
48
|
+
`collections/ExampleCollection.ts`
|
|
49
|
+
```ts
|
|
50
|
+
import { CollectionConfig } from 'payload/types';
|
|
51
|
+
|
|
52
|
+
const ExampleCollection: CollectionConfig = {
|
|
51
53
|
slug: 'example-collection',
|
|
52
54
|
fields: [
|
|
53
55
|
{
|