Skip to content

Incomplete, previously valid content bypasses new validation rules #395

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

Open
toondkn opened this issue May 8, 2025 · 9 comments
Open

Incomplete, previously valid content bypasses new validation rules #395

toondkn opened this issue May 8, 2025 · 9 comments
Assignees
Milestone

Comments

@toondkn
Copy link

toondkn commented May 8, 2025

Steps to reproduce:

  1. In the sveltia config, create a new collection with an optional field
  2. Start and open sveltia cms
  3. Add a new item to the created collection, keep the optional field empty
  4. Edit the config, make the previously optional field required
  5. Reload the cms
  6. Duplicate the item that was created in step 3
  7. Save the duplicate
  8. Observe the required field validation is bypassed

This opens a gap where bad data can easily enter the system, causing confusion for cms users and extra work for implementers.

@kyoshino
Copy link
Member

kyoshino commented May 8, 2025

Thanks for the heads-up. Will check what’s happening.

@kyoshino kyoshino self-assigned this May 8, 2025
@kyoshino
Copy link
Member

kyoshino commented May 8, 2025

@toondkn Can you provide the (partial) config to reproduce the issue?

@kyoshino
Copy link
Member

I cannot reproduce the issue locally; the validation works as expected for a duplicate entry. It may be related to a specific field configuration, or perhaps your site config is cached.

@kyoshino kyoshino added the question Further information is requested label May 10, 2025
@toondkn
Copy link
Author

toondkn commented May 14, 2025

Thanks for checking. I tried reproducing with a minimal example, and it indeed works as expected, great! I will try to replicate the behavior with the exact collection config and report back.

@toondkn
Copy link
Author

toondkn commented May 14, 2025

Managed to reproduce the issue with the following collection config and piece of content.

The exact collection config entry, for completeness' sake:

{
    label: 'Laadpaal modellen',
    label_singular: 'Laadpaal model',
    name: 'chargerModels',
    icon: 'ev_station',
    folder: 'src/content/charger-models',
    extension: 'json',
    create: true,
    identifier_field: 'name',
    editor: {
        preview: false,
    },
    summary: '{{brand}} - {{name}}',
    slug: '{{name}}',
    fields: [
        {
            label: 'Merk',
            name: 'brand',
            widget: 'relation',
            collection: 'chargerBrands',
        },
        {
            label: 'Modelnaam',
            name: 'name',
            widget: 'string',
        },
        weightField,
        {
            label: 'Laadsnelheid',
            name: 'chargeSpeed',
            widget: 'select',
            options: chargeSpeedOptions,
        },
        {
            label: 'Laadtype',
            name: 'chargeType',
            widget: 'select',
            options: chargeTypeOptions,
        },
        {
            label: 'Laadrichting',
            name: 'chargeDirection',
            widget: 'select',
            options: chargeDirectionOptions,
        },
        {
            label: 'Kabel type',
            name: 'cableType',
            widget: 'select',
            options: [
                {
                    label: 'Vaste kabel',
                    value: 'fixed',
                },
                {
                    label: 'Socket',
                    value: 'socket',
                },
            ],
        },
        {
            label: 'Bevestiging',
            name: 'formFactor',
            widget: 'select',
            options: [
                {
                    label: 'Muur',
                    value: 'wall',
                },
                {
                    label: 'Grond',
                    value: 'pole',
                },
            ],
        },
        {
            label: 'Features',
            name: 'features',
            widget: 'select',
            multiple: true,
            options: [
                {
                    label: 'Laden op zonne-energie',
                    value: 'solar',
                },
                {
                    label: 'Mobiele app',
                    value: 'app',
                },
                {
                    label: 'LCD scherm',
                    value: 'lcd',
                },
            ],
        },
        {
            label: 'Hoofdafbeelding',
            name: 'image',
            widget: 'image',
        },
        {
            label: 'Beschrijving',
            name: 'description',
            widget: 'markdown',
            buttons: markdownButtons,
        },
        {
            label: 'Voordelen',
            label_singular: 'Voordeel',
            name: 'sellingPoints',
            widget: 'list',
            fields: [
                {
                    label: 'Voordeel',
                    name: 'name',
                    widget: 'text',
                },
            ],
        },
        {
            label: 'Kleuren',
            label_singular: 'Kleur',
            name: 'colors',
            widget: 'list',
            fields: [
                {
                    label: 'Naam kleur',
                    name: 'colorName',
                    widget: 'string',
                    required: false,
                },
                {
                    label: 'Kleurcode',
                    name: 'colorCode',
                    widget: 'color',
                },
                {
                    label: 'Afbeeldingen',
                    name: 'images',
                    widget: 'list',
                    fields: [{
                        label: 'Afbeelding',
                        name: 'image',
                        widget: 'image',
                    }],
                },
            ],
        },
    ],
},

This is an existing incomplete entry, that when duplicated, can be saved while some required fields are not filled in:

{
  "brand": "smappee",
  "name": "EV Ultra 240S",
  "weight": null,
  "chargeType": "dc",
  "chargeDirection": "uni",
  "cableType": "fixed",
  "formFactor": "pole",
  "image": "/images/EV-Ultra-White-S-frontside.jpg",
  "description": "240kW DC lader",
  "sellingPoints": [
    {
      "name": "Slim energiemanagement"
    },
    {
      "name": "Compact en strak design"
    }
  ],
  "type": "commercial"
}

Note that the widget for field with name "chargeSpeed" is marked as required in the Sveltia interface with a red asterisk, yet a duplicate of it can be saved even when that field is not filled in.

@kyoshino
Copy link
Member

Thanks! Will check back later today.

@kyoshino kyoshino removed the question Further information is requested label May 14, 2025
@kyoshino
Copy link
Member

I can confirm the issue, which actually happens even without duplicating an entry. I’ll overhaul the validation code to fix the problem.

@kyoshino kyoshino changed the title Duplicating previous valid content bypasses new validation rules Incomplete, previously valid content bypasses new validation rules May 14, 2025
@kyoshino
Copy link
Member

kyoshino commented May 21, 2025

Sorry to keep you waiting 🙇🏼 I realized that the current entry validator isn’t quite right. So I have to rewrite the whole validator code with automated tests written. I plan to finish it in a few weeks.

@toondkn
Copy link
Author

toondkn commented May 22, 2025

Hey no pressure! Thanks for building this great project.

@kyoshino kyoshino added this to the 1.0 RC milestone May 27, 2025
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

2 participants