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

Copy/paste of objects in array fields does not work with anonymous objects #7607

Open
stianmartinsen opened this issue Oct 9, 2024 · 0 comments

Comments

@stianmartinsen
Copy link

stianmartinsen commented Oct 9, 2024

Describe the bug

Copying and pasting array items (introduced in Sanity v3.54.0 in pull request #7292) requires the objects to have a name. If not provided, the error "Value of type "object" is not allowed in this array field" appears on the screen.

To Reproduce

This is an example of a simple schema that has an "Accordion" field. This is an array with anonymous objects.

import {defineType, defineField, defineArrayMember} from 'sanity'

export const page = defineType({
  type: 'document',
  name: 'page',
  fields: [
    defineField({
      type: 'string',
      name: 'title',
    }),
    defineField({
      type: 'slug',
      name: 'slug',
      options: {
        source: 'title',
        maxLength: 96,
      },
    }),
    defineField({
      type: 'array',
      name: 'accordion',
      title: 'Accordion',
      of: [
        defineArrayMember({
          type: 'object',
          fields: [
            defineField({
              type: 'string',
              name: 'title',
            }),
            defineField({
              type: 'text',
              name: 'content',
            }),
          ],
        }),
      ],
    }),
  ],
})

To replicate the issue, try to open this in the Sanity studio, create a page with an accordion array item, and lastly try to copy/paste the row.

Expected behavior

Because naming your objects in array fields isn't mandatory (if you don't have multiple objects available in the same array field), I would expect copy/pasting anonymous objects in array fields to work.

Screenshots

This is the error message I get when trying to copy and paste an accordion item:

Skjermbilde 2024-10-09 kl  15 41 36

Which versions of Sanity are you using?

@sanity/eslint-config-studio   4.0.0 (up to date)
@sanity/vision                3.60.0 (up to date)
sanity                        3.60.0 (up to date)
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