#How to reuse form builder blocks

5 messages · Page 1 of 1 (latest)

mellow lake
#

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

eager brookBOT
storm thorn
#

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;

mellow lake
#

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

mellow lake
#

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