payload-user-generated-fields-plugin
v0.1.19
Published
A plugin for Payload CMS v3 that allows admin users to create custom fields for collections.
Downloads
163
Readme
Payload User Generated Fields Plugin
A Payload CMS plugin that lets admins define dynamic field configurations in one collection and capture user-entered values in another.
Install
bun add payload-user-generated-fields-pluginUsage
Add the plugin to your payload.config.ts:
import { buildConfig } from 'payload'
import { pluginUserGeneratedFields } from 'payload-user-generated-fields-plugin'
export default buildConfig({
collections: [
{
slug: 'post-categories',
fields: [{ name: 'title', type: 'text' }],
},
{
slug: 'posts',
fields: [{ name: 'postTitle', type: 'text', required: true }],
},
],
plugins: [
pluginUserGeneratedFields({
collections: [
{
configCollection: {
slug: 'post-categories',
},
valuesCollection: {
slug: 'posts',
groupName: 'Post Category Fields',
relationshipFieldName: 'post-categories',
useDefaultRelationshipField: true,
},
},
],
debug: false,
}),
],
})How It Works
- The plugin augments the
configCollectionwith:- a blocks field (
customFieldsOptionsby default) for defining dynamic form fields - a hidden JSON field (
customFieldsConfigby default) that stores normalized configuration
- a blocks field (
- The plugin augments the
valuesCollectionwith:- a relationship field to the config collection (optional if you provide your own relationship)
- a group containing:
- hidden config storage JSON
- hidden values JSON rendered through a custom admin field component
Configuration
The plugin accepts:
collections: array of config/values collection pair definitionsdebug: enables internal hidden JSON field visibility and debug logs
For exported config/types:
- main plugin:
payload-user-generated-fields-plugin - RSC export:
payload-user-generated-fields-plugin/rsc - client export:
payload-user-generated-fields-plugin/client - types export:
payload-user-generated-fields-plugin/types
Local Development
- Copy
dev/.env.exampletodev/.envand update values. - Install dependencies:
bun install- Start the dev app:
bun run dev- Open
http://localhost:3000/admin.
Testing
- Integration tests (Vitest):
bun run test:int- End-to-end tests (Playwright):
bun run test:e2e- Full suite:
bun run testBuild and Publish
Build distributable files:
bun run buildPublishing uses publishConfig to ship dist entry points for:
../types./client./rsc
