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.33k stars 1.48k forks source link

Validation on Blocks doesn't stop a page from saving #8071

Open PavelGolodoniuc opened 1 week ago

PavelGolodoniuc commented 1 week ago

Link to reproduction

No response

Describe the Bug

If you have a simple Block with a required field or fields with any kind of validation logic, upon saving the page, it momentarily highlights the errored fields and flashes the error message on top of the block but still saves the page. The block is added to the page via a Lexical editor.

To Reproduce

Block:

export const Hero: Block = {
    slug: "hero",
    fields: [
        {
            name: "title",
            type: "text",
            required: true,     // <<<<<<<<<<<<<<<<<<<
        },
        {
            name: "subtitle",
            type: "text",
        },
    ],
};

Lexical config:

export const defaultConfig = <LexicalEditorProps>{

    features: ({ defaultFeatures }) => [
        ...defaultFeatures,
        HeadingFeature({
            enabledHeadingSizes: [ "h1", "h2", "h3", "h4" ],
        }),
        LinkFeature({
            enabledCollections: [
                Pages.slug
            ],
            fields: [
                linkRel
            ],
        }),
        BlocksFeature({
            blocks: [
                Hero,     // <<<<<<<<<<<<<<<<<<<
            ],
        }),
    ]
};

Payload Version

2.27.0

Adapters and Plugins

"@payloadcms/richtext-lexical": "^0.11.3"

georgecartridge commented 1 week ago

+1 - I'm also finding this!