Skip to content

Commit

Permalink
feat: explicitly exports fields for reuse payloadcms#35 (payloadcms#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobsfletch authored May 15, 2023
1 parent 590d4e0 commit 3bdf1bd
Show file tree
Hide file tree
Showing 9 changed files with 1,649 additions and 8,940 deletions.
54 changes: 40 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ export default config;
}
```

You can also provide your own custom field definitions by passing a new [Payload Block](https://payloadcms.com/docs/fields/blocks#block-configs) object into `fields`.

- `redirectRelationships`

An array of collection slugs that, when enabled, are populated as options in form redirect fields.
Expand Down Expand Up @@ -115,6 +113,10 @@ export default config;
```ts
formOverrides: {
slug: "contact-forms",
access: {
read: () => true,
update: () => false,
},
fields: [
{
name: "custom-field",
Expand All @@ -132,66 +134,68 @@ export default config;
```js
formSubmissionOverrides: {
slug: "leads";
slug: "leads",
}
```
## Fields
Each field represents a form input. To override default settings pass either a boolean value or a partial [Payload Block](https://payloadcms.com/docs/fields/blocks) keyed to the block's slug.
Each field represents a form input. To override default settings pass either a boolean value or a partial [Payload Block](https://payloadcms.com/docs/fields/blocks) _keyed to the block's slug_. See [Field Overrides](#field-overrides) for more details on how to do this.
- Text
> NOTE: "fields" here are in reference to the _fields to build forms with_, not to be confused with the _fields of a collection_ which are set via `formOverrides.fields`.
- `text`
- `name`: string
- `label`: string
- `defaultValue`: string
- `width`: string
- `required`: checkbox
- Textarea
- `textarea`
- `name`: string
- `label`: string
- `defaultValue`: string
- `width`: string
- `required`: checkbox
- Select
- `select`
- `name`: string
- `label`: string
- `defaultValue`: string
- `width`: string
- `options`: array
- `required`: checkbox
- Email
- `email`
- `name`: string
- `label`: string
- `defaultValue`: string
- `width`: string
- `required`: checkbox
- State
- `state`
- `name`: string
- `label`: string
- `defaultValue`: string
- `width`: string
- `required`: checkbox
- Country
- `country`
- `name`: string
- `label`: string
- `defaultValue`: string
- `width`: string
- `required`: checkbox
- Checkbox
- `checkbox`
- `name`: string
- `label`: string
- `defaultValue`: checkbox
- `width`: string
- `required`: checkbox
- Number
- `number`
- `name`: string
- `label`: string
- `defaultValue`: number
- `width`: string
- `required`: checkbox
- Message
- `message`
- `message`: richText
- Payment
- `payment`
- `name`: string
- `label`: string
- `defaultValue`: number
Expand All @@ -205,6 +209,28 @@ Each field represents a form input. To override default settings pass either a b
- `valueType`: string - `static`, `valueOfField`
- `value`: string - only if `valueType` is `static`
### Field Overrides
You can also provide your own custom field definitions by passing a new [Payload Block](https://payloadcms.com/docs/fields/blocks#block-configs) object into `fields`. You can override or extend any existing fields by first importing the `fields` from the plugin:
```ts
import { fields } from "@payloadcms/plugin-form-builder";
```
Then merging it into your own custom field:
```ts
fields: {
text: {
...fields.text,
labels: {
singular: "Custom Text Field",
plural: "Custom Text Fields",
}
}
}
```
## Email
This plugin relies on the [email configuration](https://payloadcms.com/docs/email/overview) defined in your `payload.init()`. It will read from your config and attempt to send your emails using the credentials provided.
Expand Down
2 changes: 1 addition & 1 deletion demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"deepmerge": "^4.2.2",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"payload": "^1.3.0"
"payload": "^1.8.2"
},
"devDependencies": {
"@types/express": "^4.17.9",
Expand Down
9 changes: 8 additions & 1 deletion demo/src/payload.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Block } from 'payload/types'

// import formBuilderPlugin from '../../dist';
// eslint-disable-next-line import/no-relative-packages
import formBuilderPlugin from '../../src'
import formBuilderPlugin, { fields } from '../../src'
import { Pages } from './collections/Pages'
import { Users } from './collections/Users'

Expand Down Expand Up @@ -68,6 +68,13 @@ export default buildConfig({
fields: {
payment: true,
colorField,
text: {
...fields.text,
labels: {
singular: 'Custom Text Field',
plural: 'Custom Text Fields',
},
},
// payment: {
// paymentProcessor: {
// options: [
Expand Down
2 changes: 1 addition & 1 deletion demo/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ app.get('/', (_, res) => {

// Initialize Payload
const start = async (): Promise<any> => {
await payload.initAsync({
await payload.init({
secret: process.env.PAYLOAD_SECRET,
mongoURL: process.env.MONGODB_URI,
express: app,
Expand Down
Loading

0 comments on commit 3bdf1bd

Please sign in to comment.