Skip to content

Invalid date with date string template transformations #6427

@LucasMeloMB

Description

@LucasMeloMB

Hello Everyone,
I'm creating my CMS configuration file and I'm having a problem with string template transformations.

Describe the bug
I created a collection of events and in it I have two datetime fields that are not mandatory, so the user may or may not fill them. In this collection I have a summary that brings the event title and the datetime with string template transformations.

My problem is that when the user does not select a datetime, the string template transformations returns "Invalid date" in the summary, and I would not like this to appear

is there any way for me to not display "Invalid date" when the user does not select a date?

To Reproduce
apply string template transformations on an empty date

Expected behavior
I don't want to display invalid date when the user doesn't select a datetime

Screenshots
image

Applicable Versions:

  • Netlify CMS version: 2.10.183
  • Git provider: GitHub
  • OS: Windows 10
  • Browser version Chrome/100.0.4896.127

CMS configuration

load_config_file: false,
site_url: location.origin,
logo_url: `${location.origin}/SmallLogo.svg`,
show_preview_links: false,
editor: {
  preview: false,
},
publish_mode: cmsRole.viewWorkFlow,
media_library: {
  name: 'disabled',
},
collections: [
  {
    label: 'Events & Recordings',
    name: 'event',
    summary: `{{title}} - {{fields.day | date('MM/DD/YYYY')}} - {{fields.end | date('MM/DD/YYYY')}}`,
    folder: cmsCollectionFolder('event'),
    create: cmsRole.canCreate,
    delete: cmsRole.canDelete,
    publish: cmsRole.canPublish,
    extension: 'json',
    slug: `{{year}}-{{month}}-{{day}}-{{slug}}`,
    fields: [
      {
        label: 'Title',
        name: 'title',
        widget: 'string',
        pattern: ['.{5,}', 'Must have at least 5 characters'],
      },
      {
        label: 'Place',
        name: 'place',
        widget: 'select',
        options: [
          { label: 'Virtual', value: 'Virtual' },
          { label: 'Local', value: 'Local' },
        ],
      },
      { label: 'Start Event', name: 'day', widget: 'datetime', default: '', time_format: false, required: false },
      { label: 'End Event', name: 'end', widget: 'datetime', default: '', time_format: false, required: false },
      { label: 'Link', name: 'link', widget: 'string' },
    ],
  }, ...

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugcode to address defects in shipped code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions