jdorn / json-editor

JSON Schema Based Editor
MIT License
5.81k stars 1.08k forks source link

Bug with arrays #560

Open n-sviridenko opened 8 years ago

n-sviridenko commented 8 years ago

Hello all! I have some problem with arrays. This problem against when I add 2+ values (screenshot: http://joxi.ru/KAgMoZlH7WL3ml), remove first one (screenshot: http://joxi.ru/LmG3ea6TDPo9ml) and after add new. After I will see broken array item (screenshot: http://joxi.ru/YmEkaKQHqPOoA6).

My code:

<div id="js-capabilities"></div>

<script>
(function() {
    var element = document.getElementById('js-capabilities');
    var editor = new JSONEditor(element, {
        theme: "bootstrap3",
        disable_collapse: true,
        disable_edit_json: true,
        disable_properties: true,
        disable_array_reorder: true,
        form_name_root: "capabilities",
        startval: [],
        schema: {
            type: "array",
            title: 'capabilities',
            items: {
                type: "object",
                options: {
                    layout: 'grid'
                },
                properties: {
                    capability_id: {
                        type: "integer",
                        required: true,
                        enum: [1, 2, 3],
                        options: {
                            enum_titles: ['a', 'b', 'c'],
                            grid_columns: 6
                        }
                    },
                    started_at: {
                        type: "string",
                        options: {
                            grid_columns: 3
                        }
                    },
                    ended_at: {
                        type: "string",
                        options: {
                            grid_columns: 3
                        }
                    }
                }
            }
        }
    });
})();
</script>
gfb107 commented 8 years ago

Provide a default value

{
            "type": "array",
            "title": "capabilities",
            "items": {
                "type": "object",
                "options": {
                    "layout": "grid"
                },
                "properties": {
                    "capability_id": {
                        "type": "integer",
                        "required": true,
                        "enum": [1, 2, 3],
                        "options": {
                            "enum_titles": ["a", "b", "c"],
                            "grid_columns": 6
                        }
                    },
                    "started_at": {
                        "type": "string",
                        "options": {
                            "grid_columns": 3
                        }
                    },
                    "ended_at": {
                        "type": "string",
                        "options": {
                            "grid_columns": 3
                        }
                    }
                },
                "default": { "capability_id": 1, "started_at": "", "ended_at": "" }
            }
        }