Like what we’re doing? Star us on GitHub!

Not possible to have an upload to be optional, is it a bug?

hunghvu
6 months ago
1 1

When I test the upload feature, it seems like an upload field is not optional. For example,

import { CollectionConfig } from "payload/types";

const Test:CollectionConfig = {
  slug: 'tests',
  fields: [
      {
        name: 'metaCoverImage',
        label: 'Cover Image',
        type: 'upload',
        relationTo: 'media',
        required: true,
      },
      {
        name: 'metaCustomOgImage',
        label: 'Custom OG Image (front-end will fallback to cover image if not presented)',
        type: 'upload',
        relationTo: 'media',
      },
    ]
}

export default Test;

The second upload field should be optional, however, it raises an exception when no upload is presented. Is this a design decision or a bug? If it is a design decision, then is there a way to have an optional upload?

image

  • DanRibbens
    Payload Team
    6 months ago

    Hey @hunghvu, it looks like a regression from the changes we made to futher validate upload and relationships. I'll get a fix out soon!

    2 replies
  • DanRibbens
    Payload Team
    6 months ago

    OK, this is fixed now, please upgrade to v1.0.30.

    Thanks for asking or I wouldn't have caught it!

  • hunghvu
    6 months ago

    Can confirm that it was fixed. I always love this lightning-fast response from the team. Keep up the great work!

Open the post
Continue the discussion in GitHub
Can't find what you're looking for?
Get help straight from the Payload team with an Enterprise License.Learn More