brutusin / json-forms

JSON Schema to HTML form generator, supporting dynamic subschemas (on the fly resolution). Extensible and customizable library with zero dependencies. Bootstrap add-ons provided
http://brutusin.org/json-forms
Apache License 2.0
607 stars 168 forks source link

Open enum support #68

Closed ychyrski closed 7 years ago

ychyrski commented 7 years ago

Having this schema

{
    "$schema": "http://json-schema.org/draft-03/schema#",
    "type": "object",
    "properties": {
        "species": {
            "title": "Species",     
            "type": "string",
            "enum": [
                "human",
                "dog",
                "cat"
            ],
            "required": true
        }       
    }
}

I would like to render a dropdown componet which would contain values from the enum section(human,cat,dog) and provide end user with the possibility to enter its own value. Any insights how to do so?

idelvall commented 7 years ago

This constraint can not be modeled with a json schema. You can fix the values to only a valid set (using enum), or you can leave it open (without enum) , but you can not have both. Said that, you can create your own json schema extension for that, and use your own keyword instead of 'enum', for example 'preferred', and then add a custom decorator to the library to achieve the desired graphical effect.

For custom decorator examples see :

ychyrski commented 7 years ago

thanks!