Skip to content
This repository was archived by the owner on Sep 9, 2024. It is now read-only.
This repository was archived by the owner on Sep 9, 2024. It is now read-only.

Impossible to use widgetsFor for a typed List #1103

Description

@drweizak

Hello everyone! I am trying to create a custom preview!
This is one of my fields in my collection

  {
      label: "Secções",
      label_singular: "Secção",
      name: "sections",
      widget: "list",
      summary: "{{fields.name}}",
      types: [coverLayout, blankSectionLayout],
    },

In my preview template I have the following code:

const PostPreview: FC<TemplatePreviewProps<IPost>> = ({
  entry,
  widgetFor,
  widgetsFor,
}) => {
  if (entry?.data?.type === "publication") {
    const { title } = entry.data;

    return (
      <div>
        {widgetsFor("sections").map((section, index) =>
          section ? (
            <div key={index}>
              <hr />
              <strong>{section.data?.title}</strong>
            </div>
          ) : null
        )}
      </div>
    );

I am getting the following error: Uncaught TypeError: widgetsFor(...).map is not a function

My interface:

export default interface IPost {
  id: UUID;
  slug: string;
  type: IPostType;
  pre_title?: string;
  title: string;
  sub_title?: string;
  description?: string;
  publish_date: string;
  sections: ISection[];
  authors: IAuthor["slug"][];
  category: ICategory["slug"];
  tags: ITag["slug"][];
}

I have tried different approaches. I have data on my section when i log the data.sections.
I found out that it's because i am using types instead of fields

Is there a way to use widgetsFor for a typed List?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpreview

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions