How to build a custom Array field component?

default discord avatar
thgh.
4 months ago
2

I'm stuck on this error on saving the field:


Cast to embedded failed for value "1" (type number) at path "erk" because of "ObjectParameterError"
  • default discord avatar
    jarrod69420
    4 months ago

    We are working to make this easier, but in the meantime - this will likely help you:

    https://github.com/payloadcms/payload/issues/2427#issuecomment-1512320542
  • default discord avatar
    thgh.
    3 months ago

    Thanks! Noticed this too late so ended up with this:



     const toggle = useEvent(({ slug, title }: CourseMaterialTaxonomy['erk'][0]) => {
        if (selectedSlugs.includes(slug)) {
          dispatchFields({
            type: 'REMOVE_ROW',
            rowIndex: selectedSlugs.indexOf(slug),
            path,
          })
        } else {
          dispatchFields({
            type: 'ADD_ROW',
            rowIndex: selectedSlugs.length,
            subFieldState: {
              id: {
                disableFormData: false,
                valid: true,
                initialValue: undefined,
                value: slug,
              },
              slug: {
                disableFormData: false,
                valid: true,
                initialValue: undefined,
                value: slug,
                passesCondition: true,
              },
              title: {
                disableFormData: false,
                valid: true,
                initialValue: undefined,
                value: title,
                passesCondition: true,
              },
            },
            path,
          })
        }
      })
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.