Files
payload/packages/plugin-form-builder/src/index.ts
Paul 7d0e909a30 feat(plugin-form-builder)!: update form builder plugin field overrides to use a function instead (#6497)
## 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)
2024-05-28 17:45:51 -03:00

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),
],
}
}