jamestagal / plenti-educenter

0 stars 1 forks source link

Use type: "id" to make name fields in components not editable in CMS #16

Closed jamestagal closed 1 year ago

jamestagal commented 1 year ago

Hi @jimafisk,

I have been thinking of implementing a way to not allow changes/edits to name fields in components from the CMS editor. I wish to do this because these name fields are bound to their svelte templates and if an editor unknowingly changes one of these fields on the frond end, the site would break. So one way to do this would be to use the uuid or type:"id" to disable in the editor. Though, even after watching your video on doing this, I haven't yet been able to get it working but here's where I am at. 😊

In the pages content, I have an aboutus.json file that uses 5 components. So I have:

  1. Created an aboutus folder within the _components folder
  2. Created the two required files: _defaults.json and _schema.json
  3. In the _defaults.json file here, I have added the default field name such as:
    {
    "name": "aboutus"
    }
  4. In the _schema.json file here, I have added the type of id to the components.name field such as:
    {
    "components.name": {
        "type": "id"
    }
    }

    Sorry for some many questions...I seem to always get stuck! 😨 Any help would be great. Thanks.

Ben

jimafisk commented 1 year ago

No worries @jamestagal, it's constantly changing and undocumented at the moment, so confusion is expected :).

The id type is actually used for randomly generating a string. This is typically used to tie together completely separate systems, like the default Plenti CMS and a database backend.

Preventing editing the name field is a common pattern, I do this in my Plenti apps as well! You can do this without an ID field by using the disabled option in a text type field instead:

{
    "name": {
        "type": "text",
        "options": [
            "disabled"
        ]
    }
}
jamestagal commented 1 year ago

Thanks again @jimafisk I am slowly getting a hang of how everything works in Plenti.

Ben