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

Impossible to use widgetsFor for a typed List #1103

Open
drweizak opened this issue Apr 19, 2024 · 0 comments
Open

Impossible to use widgetsFor for a typed List #1103

drweizak opened this issue Apr 19, 2024 · 0 comments
Labels
bug Something isn't working preview
Milestone

Comments

@drweizak
Copy link

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?

@KaneFreeman KaneFreeman added bug Something isn't working preview labels Apr 26, 2024
@KaneFreeman KaneFreeman added this to the 4.x milestone Apr 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working preview
Projects
None yet
Development

No branches or pull requests

2 participants