## Description
Changes the `fields` override for form builder plugin to use a function
instead so that we can actually override existing fields which currently
will not work.
```ts
//before
fields: [
{
name: 'custom',
type: 'text',
}
]
// current
fields: ({ defaultFields }) => {
return [
...defaultFields,
{
name: 'custom',
type: 'text',
},
]
}
```
## Type of change
- [x] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import type { Config } from 'payload/config'
|
|
|
|
import type { FormBuilderPluginConfig } from './types.js'
|
|
|
|
import { generateSubmissionCollection } from './collections/FormSubmissions/index.js'
|
|
import { generateFormCollection } from './collections/Forms/index.js'
|
|
|
|
export { fields } from './collections/Forms/fields.js'
|
|
export { getPaymentTotal } from './utilities/getPaymentTotal.js'
|
|
|
|
export const formBuilderPlugin =
|
|
(incomingFormConfig: FormBuilderPluginConfig) =>
|
|
(config: Config): Config => {
|
|
const formConfig: FormBuilderPluginConfig = {
|
|
...incomingFormConfig,
|
|
fields: {
|
|
checkbox: true,
|
|
country: true,
|
|
email: true,
|
|
message: true,
|
|
number: true,
|
|
payment: false,
|
|
select: true,
|
|
state: true,
|
|
text: true,
|
|
textarea: true,
|
|
...incomingFormConfig.fields,
|
|
},
|
|
}
|
|
|
|
return {
|
|
...config,
|
|
collections: [
|
|
...(config?.collections || []),
|
|
generateFormCollection(formConfig),
|
|
generateSubmissionCollection(formConfig),
|
|
],
|
|
}
|
|
}
|