Add placeholder to form builder plugin

default discord avatar
face44
2 months ago
2

I'm using

@payloadcms/plugin-form-builder

in a project and wandering if there is a way to add fields within the predefined fields?


As an example, I want to add placeholder to all the available fields like text, message, number, etc. I'm dead sure the screenshot is self explanatory. 😆



Thanks



@jacobsfletch tagging you because you know form-builder inside out. 🙂

  • discord user avatar
    jacobsfletch
    Payload Team
    2 months ago

    @face44 you should be able to do this using field overrides described here:

    https://github.com/payloadcms/plugin-form-builder#field-overrides

    . Basically just add a new field to the

    fields.text

    property in your plugin config.

  • default discord avatar
    face44
    2 months ago

    Thank you @jacobsfletch.


    The following code works but requires a

    @ts-ignore

    , the ts error is also attached.


    formBuilder({
          fields: {
            payment: false,
            state: false,
            country: false,
            text: {
              ...fields.text,
              fields: [
                //@ts-ignore
                ...fields.text.fields,
                {
                  type: 'text',
                  name: 'placeholder',
                },
              ],
            },
          },
          formOverrides: {
            fields: [{ name: 'webhook', type: 'text' }],
          },
        }),

    Am I doing it right or is my code is obviously crap?

    image.png
Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.