json-schema-form / angular-schema-form

Generate forms from a JSON schema, with AngularJS!
https://json-schema-form.github.io/angular-schema-form
MIT License
2.47k stars 653 forks source link

Adding array breaks form #838

Closed therecluse26 closed 7 years ago

therecluse26 commented 7 years ago

I have this schema built that I'm trying to add an array to, and whenever I do, it just breaks the entire form and nothing outputs. I'm not sure what I'm doing wrong, if you could help me out, I'd appreciate it a ton! When I change the one array in here to object instead, the form renders properly, but when I change it to an array, the entire form stops rendering and no error outputs to the log.

My model is empty, and I'm just using ["*"] currently for my form.

{
    "type": "object",
    "properties": {
        "interface": {
            "type": "string",
            "title": "Interface",
            "description": "<div class='formlabel'>Network interface</div>",
            "required": true
        },
        "host": {
            "type": "string",
            "title": "Host",
            "description": "<div class='formlabel'>Host that installation server should run on</div>",
            "required": true
        },
        "port": {
            "type": "integer",
            "title": "Port",
            "description": "<div class='formlabel'>Port for installation server</div>",
            "required": true
        },
        "auth": {
            "type": "string",
            "title": "Auth",
            "length": "4"
        },
        "autosave_config": {
            "type": "boolean",
            "title": "Autosave Config",
            "description": "<div class='formlabel'>Autosave Configuration</div>"
        },
        "sync_time": {
            "type": "boolean",
            "title": "Sync Time",
            "description": "<div class='formlabel'></div>"
        },
        "dev": {
            "type": "object",
            "title": "Disks",
            "description": "System Disks",
            "properties": {
                "sd": {
                    "type": "array",
                    "title": "Disk1",
                    "items": {
                        "partition": {
                            "type": "object",
                            "title": "Partition",
                            "properties": {
                                "parttype": {
                                    "type": "string",
                                    "title": "Partition Type"
                                },
                                "mountpoint": {
                                    "type": "string",
                                    "title": "Mount Point"
                                },
                                "opts": {
                                    "type": "string",
                                    "title": "Options"
                                },
                                "dump": {
                                    "type": "boolean",
                                    "title": "Dump"
                                },
                                "pass": {
                                    "type": "boolean",
                                    "title": "Pass"
                                }
                            }
                        },
                        "label": {
                            "type": "string",
                            "title": "Label"
                        }
                    }
                },
                "cdrom": {
                    "type": "object",
                    "title": "CD-ROM",
                    "description": "CD-Rom Drive",
                    "properties": {
                        "part1": {
                            "type": "object",
                            "title": "Partition 1",
                            "properties": {
                                "parttype": {
                                    "type": "string",
                                    "title": "Partition Type"
                                },
                                "mountpoint": {
                                    "type": "string",
                                    "title": "Mount Point"
                                },
                                "opts": {
                                    "type": "string",
                                    "title": "Options"
                                },
                                "dump": {
                                    "type": "boolean",
                                    "title": "Dump"
                                },
                                "pass": {
                                    "type": "boolean",
                                    "title": "Pass"
                                }
                            }
                        },
                        "label": {
                            "type": "string",
                            "title": "Label"
                        }
                    }
                }
            }
        }
    }
}
Anthropic commented 7 years ago

@therecluse26 your array is incorrectly defined, you don't have properties defined in an array, the item definition IS a property of its own. If you want to define an object with properties you have to define the object within the array first.

{
    "type": "object",
    "properties": {
        "interface": {
            "type": "string",
            "title": "Interface",
            "description": "<div class='formlabel'>Network interface</div>",
            "required": true
        },
        "host": {
            "type": "string",
            "title": "Host",
            "description": "<div class='formlabel'>Host that installation server should run on</div>",
            "required": true
        },
        "port": {
            "type": "integer",
            "title": "Port",
            "description": "<div class='formlabel'>Port for installation server</div>",
            "required": true
        },
        "auth": {
            "type": "string",
            "title": "Auth",
            "length": "4"
        },
        "autosave_config": {
            "type": "boolean",
            "title": "Autosave Config",
            "description": "<div class='formlabel'>Autosave Configuration</div>"
        },
        "sync_time": {
            "type": "boolean",
            "title": "Sync Time",
            "description": "<div class='formlabel'></div>"
        },
        "dev": {
            "type": "object",
            "title": "Disks",
            "description": "System Disks",
            "properties": {
                "sd": {
                    "type": "array",
                    "title": "Disk1",
                    "items": {
            "type": "object",
            "properties":{
                        "partition": {
                            "type": "object",
                            "title": "Partition",
                            "properties": {
                                "parttype": {
                                    "type": "string",
                                    "title": "Partition Type"
                                },
                                "mountpoint": {
                                    "type": "string",
                                    "title": "Mount Point"
                                },
                                "opts": {
                                    "type": "string",
                                    "title": "Options"
                                },
                                "dump": {
                                    "type": "boolean",
                                    "title": "Dump"
                                },
                                "pass": {
                                    "type": "boolean",
                                    "title": "Pass"
                                }
                            }
                        },
                        "label": {
                            "type": "string",
                            "title": "Label"
                        }
                    }
                    }
                },
                "cdrom": {
                    "type": "object",
                    "title": "CD-ROM",
                    "description": "CD-Rom Drive",
                    "properties": {
                        "part1": {
                            "type": "object",
                            "title": "Partition 1",
                            "properties": {
                                "parttype": {
                                    "type": "string",
                                    "title": "Partition Type"
                                },
                                "mountpoint": {
                                    "type": "string",
                                    "title": "Mount Point"
                                },
                                "opts": {
                                    "type": "string",
                                    "title": "Options"
                                },
                                "dump": {
                                    "type": "boolean",
                                    "title": "Dump"
                                },
                                "pass": {
                                    "type": "boolean",
                                    "title": "Pass"
                                }
                            }
                        },
                        "label": {
                            "type": "string",
                            "title": "Label"
                        }
                    }
                }
            }
        }
    }
}
therecluse26 commented 7 years ago

Thank you! That was driving me nuts! I must have missed that in the documentation