Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

How to reuse form builder blocks

default discord avatar
epnk4202 years ago
2

Hi, I want to use the built in form builder blocks (fields) in my own custom blocks that uses the form builder block fields. Is there a way to import them to use, I can’t seem to figure it out. For example I want to have a form section block with text etc that lets me add form builder fields. I was able to do it by adding an array field with the name of each form field I want in the section, but that’s not very user friendly for end users. Thanks

  • default discord avatar
    fatso88552 years ago

    This is how I achieved it:



    import { Block } from 'payload/types';
    import richText from '../fields/richText';
    
    const FormField = {
      title: "title",
    }
    
    type FormField = (typeof FormField)[keyof typeof FormField];
    
    
    const FormLink: Block = {
      slug: 'formLink',
      labels: {
        singular: 'Form',
        plural: 'Forms',
      },
      fields: [
        {
          name: FormField.title,
          type: "text",
        },
        richText,
        {
          name: "form",
          label: "Form",
          type: "relationship",
          relationTo: "forms"
        },
      ],
    };
    
    export default FormLink;
  • default discord avatar
    epnk4202 years ago
    @337389254164480003

    thanks I’ll try that out, didn’t even think about using a relationship



    @337389254164480003

    thanks again for the suggestion, tried it out and that works for my purposes.

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.