Skip to content

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

@DanRibbens

Description

@DanRibbens

Discussed in #1023

Originally posted by hunghvu August 29, 2022
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions