jsonform / jsonform

Build forms from JSON Schema. Easily template-able. Compatible with Bootstrap 3 out of the box.
https://jsonform.github.io/jsonform/playground/index.html
MIT License
2.73k stars 554 forks source link

Form Styling for array elements #371

Closed sabrineChe closed 2 years ago

sabrineChe commented 2 years ago

Hi, I want to define a uiForm for my schema which includes an array. My schema looks like that: { "type": "object", "properties": { "schemaId": { "type": "string", "title": "Schema Record Identifier" }, "acl": { "type": "array", "title": "ACL", "items": { "type": "object", "properties": { "sid": { "type": "string", "title": "sid", "default": "SELF", "enum": ["SELF", "admin", "guest"] }, "permission": { "type": "string", "title": "Permission", "default": "ADMINISTRATE", "enum": ["READ", "ADMINISTRATE"] } } } } } }

And my uiForm looks like that: { "type": "fieldset", "title": "Schema Record", "items": [ "schemaId", { "type": "array", "title": "ACL", "htmlClass": "acl", "items": [ "acl[].sid", "acl[].permission" ] } ] }

Unfortunately, only the first element of the array, wich is "sid" appears. The "permission" attribute doesn't appear in the form.

tchapi commented 2 years ago

Hi Can you post your complete schema so I can reproduce it in the playground ?

Thanks

sabrineChe commented 2 years ago

This is the schema:

{
  "schema": {

        "schemaId": {
            "type": "string",
            "title": "Schema Record Identifier"
        },
        "mimeType": {
            "type": "string",
            "title": "mime Type",
            "enum": ["application/json", "application/xml"]
        },
        "type": {
            "type": "string",
            "title": "Type",
            "enum": ["JSON", "XML"]
        },
        "label": {
            "type": "string",
            "title": "Label"
        },
        "definition": {
            "type": "string",
            "title": "Definition"
        },
        "comment": {
            "type": "string",
            "title": "Comment"
        },
        "acl": {
            "type": "array",
            "title": "ACL",
            "items": {
                "type": "object",
                "properties": {
                    "sid": {
                        "type": "string",
                        "title": "sid",
                        "default": "SELF",
                        "enum": ["SELF", "admin", "guest"]
                    },
                    "permission": {
                        "type": "string",
                        "title": "Permission",
                        "default": "ADMINISTRATE",
                        "enum": ["READ", "ADMINISTRATE"]
                    }
                }
            }
        }
    }, "form": [
    "schemaId",
        "mimeType",
        "type",
        "label",
        "definition",
        "comment",
        {"type": "array",
            "title": "ACL",
            "htmlClass": "acl",
            "items": [
                "acl[].sid",
                "acl[].permission"
            ]
        }]}
tchapi commented 2 years ago

You're looking for :

"items": [
        "acl[]"
    ]

or else you need to define a new object

sabrineChe commented 2 years ago

And if my array includes some attributes, that i don't want to list them in the form. How can i make it? Let's say my schema includes an array like that: "acl": { "type": "array", "title": "ACL", "items": { "type": "object", "properties": { "id": { "type": "string", "title": "id" }, "sid": { "type": "string", "title": "sid", "default": "SELF", "enum": ["SELF", "admin", "guest"] }, "permission": { "type": "string", "title": "Permission", "default": "ADMINISTRATE", "enum": ["READ", "ADMINISTRATE"] } } } }

and i want to show only two attributes "sid" and "permission". How can i define my uiForm?

tchapi commented 2 years ago

I guess this is not really possible at the moment unfortunately

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.