Files
payloadcms/test/plugin-form-builder/seed/index.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

172 lines
3.8 KiB
TypeScript

import type { Payload, PayloadRequest } from 'payload'
import { formsSlug, formSubmissionsSlug, pagesSlug } from '../shared.js'
export const seed = async (payload: Payload): Promise<boolean> => {
payload.logger.info('Seeding data...')
const req = {} as PayloadRequest
try {
await payload.create({
collection: 'users',
data: {
email: 'demo@payloadcms.com',
password: 'demo',
},
req,
})
await payload.create({
collection: pagesSlug,
data: {
slug: 'home',
title: 'Home page',
},
req,
})
const { id: formID } = await payload.create({
collection: formsSlug,
data: {
confirmationType: 'message',
confirmationMessage: {
root: {
children: [
{
children: [
{
detail: 0,
format: 0,
mode: 'normal',
style: '',
text: 'Confirmed',
type: 'text',
version: 1,
},
],
direction: 'ltr',
format: '',
indent: 0,
type: 'paragraph',
version: 1,
textFormat: 0,
textStyle: '',
},
],
direction: 'ltr',
format: '',
indent: 0,
type: 'root',
version: 1,
},
},
fields: [
{
name: 'name',
blockType: 'text',
label: 'Name',
required: true,
},
{
name: 'email',
blockType: 'email',
label: 'Email',
required: true,
},
],
title: 'Contact Form',
},
})
const { id: dateFormID } = await payload.create({
collection: formsSlug,
data: {
confirmationType: 'message',
confirmationMessage: {
root: {
children: [
{
children: [
{
detail: 0,
format: 0,
mode: 'normal',
style: '',
text: 'Confirmed',
type: 'text',
version: 1,
},
],
direction: 'ltr',
format: '',
indent: 0,
type: 'paragraph',
version: 1,
textFormat: 0,
textStyle: '',
},
],
direction: 'ltr',
format: '',
indent: 0,
type: 'root',
version: 1,
},
},
fields: [
{
name: 'name',
blockType: 'text',
label: 'Name',
required: true,
},
{
name: 'email',
blockType: 'email',
label: 'Email',
required: true,
},
{
name: 'date',
width: null,
required: null,
blockType: 'date',
},
],
title: 'Booking Form',
},
})
await payload.create({
collection: formSubmissionsSlug,
data: {
form: formID,
submissionData: [
{
field: 'name',
value: 'Test Submission',
},
{
field: 'email',
value: 'tester@example.com',
},
],
},
})
await payload.create({
collection: pagesSlug,
data: {
slug: 'contact',
form: formID,
title: 'Contact',
},
})
return true
} catch (err) {
console.error(err)
return false
}
}