ValidationError: The following field is invalid

default discord avatar
shakibdshy
8 months ago
1 1

Collections

const Surah: CollectionConfig = {
    slug: "surah",
    admin: {
        useAsTitle: "name",
        defaultColumns: [
            "name",
            "id",
            'variations',
            "publishDate",
            'status'
        ],
        group: "Content"
    },
    access: {
        read: ({ req: { user } }) => { 
            if (user) {
                return true;
            }

            return {
                and: [
                    {
                        publishDate: {
                            less_than: new Date().toJSON(),
                        },
                        _status: {
                            equals: 'published',
                        },
                    },
                ],
            };
        }
    },
    versions: {
        drafts: true,
    },
    fields: [
        {
            name: "name",
            type: "text",
            localized: true,
        },
{
            name: 'quranPage',
            type: 'relationship',
            relationTo: 'quranPage'
            required: true,
            hasMany: true,
            admin: {
                position: 'sidebar',
            },
        },
    ]
}
export default Surah;

Variations Collection

const QuranPage: CollectionConfig = {
    slug: 'quranPage',
    admin: {
        useAsTitle: 'name',
        defaultColumns: ['name', 'id', 'archived'],
        group: 'Content',
    },
    access: {
        read: () => true,
    },
    fields: [
        {
            name: 'name',
            type: 'text',
            localized: true,
        },
        {
            name: 'summary',
            type: 'ui',
            admin: {
                position: 'sidebar',
                components: {
                    Field: QuranPageSummary,
                }
            }
        }
    ],
}

export default QuranPage;

When I try to save this collection this showing ValidationError Error

[16:30:52] ERROR (payload): ValidationError: The following field is invalid: quranPage
    at new ExtendableError (E:\MERN Project\quranicdeen\quranicdeen-admin\node_modules\payload\src\errors\APIError.ts:26:11)
    at new APIError (E:\MERN Project\quranicdeen\quranicdeen-admin\node_modules\payload\src\errors\APIError.ts:43:5)
    at new ValidationError (E:\MERN Project\quranicdeen\quranicdeen-admin\node_modules\payload\src\errors\ValidationError.ts:8:5)
    at beforeChange (E:\MERN Project\quranicdeen\quranicdeen-admin\node_modules\payload\src\fields\hooks\beforeChange\index.ts:52:11)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at update (E:\MERN Project\quranicdeen\quranicdeen-admin\node_modules\payload\src\collections\operations\update.ts:202:16)
    at updateHandler (E:\MERN Project\quranicdeen\quranicdeen-admin\node_modules\payload\src\collections\requestHandlers\update.ts:23:17)

MongoDb

image

  • discord user avatar
    jmikrut
    Payload Team
    8 months ago

    Hey @shakibdshy — this does not appear to be an issue with Payload and is more likely related to your config itself. I'm going to convert this to a discussion but we can keep conversation going there.

    I do not see a field called quranPage anywhere in the configs that you've provided. Where is that field located? This error is generated by Payload when a provided field's value is not valid.

    1 reply
  • default discord avatar
    shakibdshy
    8 months ago

    @jmikrut It's my bad. I'm already editing this post. Can you please check it now?

Open the post
Continue the discussion in GitHub
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.