Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting defaultValue results an error when trying to edit new list item #288

Open
Phoenix-Alpha opened this issue Jun 23, 2022 · 2 comments

Comments

@Phoenix-Alpha
Copy link

I am creating a custom block and if I set defaultValue for a list item, it causes an error.
image

@Phoenix-Alpha
Copy link
Author

Phoenix-Alpha commented Jun 23, 2022

Here is my blockSchema:

export const featureBlockSchema: TinaTemplate = {
  name: "feature",
  label: "Feature",
  ui: {
    previewSrc: "/blocks/feature.png",
    defaultItem: {
      heading: "Key Features",
      text: "Integer posuere erat a ante venenatis dapibus posuere velit aliquet",
      features: [
        {
          image: {
            image: "https://res.cloudinary.com/tina-io/image/upload/path/to/image.jpg",
            size: "medium",
          },
          title: "Heading",
          text: "Integer posuere erat a ante venenatis dapibus posuere velit aliquet",
        }
      ],
      design: {
        bgColor: "white",
        borderTop: true,
        borderBottom: false,
      }
    },
  },
  fields: [
    {
      type: "string",
      label: "Heading",
      name: "heading",
    },
    {
      type: "string",
      label: "Text",
      name: "text",
      ui: {
        component: "textarea",
      },
    },
    {
      type: "object",
      label: "Features",
      name: "features",
      ui: {
        itemProps: (item) => ({ label: item.title }),
        defaultValue:  {
          image: {
            image: "https://res.cloudinary.com/tina-io/image/upload/path/to/image.jpg",
            size: "medium",
          },
          title: "Heading",
          text: "Integer posuere erat a ante venenatis dapibus posuere velit aliquet",
        }
      },
      list: true,
      fields: [
        {
          type: "object",
          label: "Image",
          name: "image",
          fields: [
            {
              type: "image",
              label: "Image",
              name: "image",
            },
            {
              type: "string",
              label: "Size",
              name: "size",
              options: [
                { label: "Small", value: "small" },
                { label: "Medium", value: "medium" },
                { label: "Large", value: "large" },
              ],
            },
            {
              type: "string",
              label: "Image Text",
              name: "imageText",
            },
          ]
        },
        {
          type: "string",
          label: "Title",
          name: "title",
        },
        {
          type: "string",
          label: "Text",
          name: "text",
        },
      ],
    },
    {
      type: "object",
      label: "Design",
      name: "design",
      fields: [
        colorSchema({ label: "Background Color", name: "bgColor" }),
        spacingSchema({ label: "Spacing Top", name: "spacingTop" }),
        spacingSchema({ label: "Spacing Bottom", name: "spacingBottom" }),
        borderSchema({ label: "Border Top", name: "borderTop" }),
        borderSchema({ label: "Border Bottom", name: "borderBottom" }),
      ]
    }
  ],
};

@Phoenix-Alpha
Copy link
Author

Phoenix-Alpha commented Jun 23, 2022

I set the defaultValue for the features list item. And it causes the error.

defaultValue:  {
    defaultValue:  {
  image: {
    image: "https://res.cloudinary.com/tina-io/image/upload/path/to/image.jpg",
    size: "medium",
  },
  title: "Heading",
  text: "Integer posuere erat a ante venenatis dapibus posuere velit aliquet",
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant