Files
payloadcms/test/plugin-form-builder/config.ts
Paul 4dfb2d24bb feat(plugin-form-builder): add new date field (#12416)
Adds a new date field to take submission values for.

It can help form serialisers render the right input for this kind of
field as the submissions themselves don't do any validation right now.

Disabled by default as to not cause any conflicts with existing projects
potentially inserting their own date blocks.

Can be enabled like this

```ts
formBuilderPlugin({
   fields: {
     date: true
   }
})
```
2025-05-21 17:34:21 +00:00

160 lines
4.1 KiB
TypeScript

import { fileURLToPath } from 'node:url'
import path from 'path'
const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
import type { BeforeEmail } from '@payloadcms/plugin-form-builder/types'
import type { Block, Field } from 'payload'
//import { nodemailerAdapter } from '@payloadcms/email-nodemailer'
import { formBuilderPlugin, fields as formFields } from '@payloadcms/plugin-form-builder'
import { lexicalEditor } from '@payloadcms/richtext-lexical'
import type { FormSubmission } from './payload-types.js'
import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js'
import { devUser } from '../credentials.js'
import { Pages } from './collections/Pages.js'
import { Users } from './collections/Users.js'
import { seed } from './seed/index.js'
const colorField: Block = {
slug: 'color',
fields: [
{
name: 'value',
type: 'text',
},
],
labels: {
plural: 'Colors',
singular: 'Color',
},
}
const beforeEmail: BeforeEmail<FormSubmission> = (emails, { req: { payload }, originalDoc }) => {
return emails
}
export default buildConfigWithDefaults({
admin: {
importMap: {
baseDir: path.resolve(dirname),
},
},
collections: [Pages, Users],
editor: lexicalEditor({}),
localization: {
defaultLocale: 'en',
fallback: true,
locales: ['en', 'es', 'de'],
},
onInit: async (payload) => {
await payload.create({
collection: 'users',
data: {
email: devUser.email,
password: devUser.password,
},
})
await seed(payload)
},
//email: nodemailerAdapter(),
plugins: [
formBuilderPlugin({
// handlePayment: handleFormPayments,
//defaultToEmail: 'devs@payloadcms.com',
fields: {
colorField,
payment: true,
text: {
...formFields.text,
labels: {
plural: 'Custom Text Fields',
singular: 'Custom Text Field',
},
},
date: {
...formFields.date,
fields: [
...(formFields.date && 'fields' in formFields.date
? formFields.date.fields.map((field) => {
if ('name' in field && field.name === 'defaultValue') {
return {
...field,
timezone: true,
admin: {
...field.admin,
description: 'This is a date field',
},
} as Field
}
return field
})
: []),
],
},
// payment: {
// paymentProcessor: {
// options: [
// {
// label: 'Stripe',
// value: 'stripe'
// },
// ],
// defaultValue: 'stripe',
// },
// },
},
beforeEmail,
formOverrides: {
// labels: {
// singular: 'Contact Form',
// plural: 'Contact Forms'
// },
fields: ({ defaultFields }) => {
return [
...defaultFields,
{
name: 'custom',
type: 'text',
},
]
},
},
formSubmissionOverrides: {
fields: ({ defaultFields }) => {
const modifiedFields: Field[] = defaultFields.map((field) => {
if ('name' in field && field.type === 'group' && field.name === 'payment') {
return {
...field,
fields: [
...field.fields, // comment this out to override payments group entirely
{
name: 'stripeCheckoutSession',
type: 'text',
},
],
}
}
return field
})
return [
...modifiedFields,
{
name: 'custom',
type: 'text',
},
]
},
},
redirectRelationships: ['pages'],
}),
],
typescript: {
outputFile: path.resolve(dirname, 'payload-types.ts'),
},
})