payloadcms / payload

Payload is the open-source, fullstack Next.js framework, giving you instant backend superpowers. Get a full TypeScript backend and admin panel instantly. Use Payload as a headless CMS or for building powerful applications.
https://payloadcms.com
MIT License
23.36k stars 1.49k forks source link

ValidationError: The following field is invalid #1799

Closed shakibdshy closed 1 year ago

shakibdshy commented 1 year ago

Collections

const Product: CollectionConfig = {
    slug: "prdocut",
    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: 'variations',
            type: 'relationship',
            relationTo: 'variations'
            required: true,
            hasMany: true,
            admin: {
                position: 'sidebar',
            },
        },
    ]
}

Variations Collection

const Variations: CollectionConfig = {
    slug: 'variations',
    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: varSummary,
                }
            }
        }
    ],
}

export default Variations;

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

jmikrut commented 1 year 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.