json-editor icon indicating copy to clipboard operation
json-editor copied to clipboard

Set enumSource conditionally

Open rmeshksar opened this issue 9 years ago • 3 comments

Hi, Here is my schema:


{
    "type" : "object",
    "properties" :
    {
        "Makes" :
        {
            "type" : "array",
            "enum" : [["Toyota","Honda","Ford"]],
            "options" : { "hidden" : true}
        },
        "Models" : 
        {
            "type" : "array",
            "enum" : [["Camry", "Civic", "Focus"]],
            "options" : { "hidden" : true}
        },
        "Filter" :
        {
            "type" : "array",
            "items" :
            {
                "type" : "object",
                "id" : "options",
                "properties" :
                {
                    "Key" :
                    {
                        "type" : "string",
                        "enum" : ["Make","Model"]
                    },
                    "Value" :
                    {
                        "type" : "string",
                        "enumSource" : ["makes", "models"],
                        "enumValue" : "{{item}}",
                        "watch" :
                        {
                            "makes" : "root.Makes",
                            "models" : "root.Models"
                        }
                    }
                }
            }
        }
    }
}

My goal is that when Key is being selected, Value enumSource to be set to Makes and when Model is selected, enumSource of the value field to be set to Models.

Is it possible? Thanks.

rmeshksar avatar Jan 13 '15 18:01 rmeshksar

I think you are looking for oneOf? https://github.com/jdorn/json-editor/blob/master/examples/advanced.html

LorenzBischof avatar Jan 15 '15 18:01 LorenzBischof

Thanks Lorenzbi, oneOf would work but I was hoping to have a better UI generated, something like cascade drop downs. I am not sure if that's possible though.

rmeshksar avatar Jan 21 '15 14:01 rmeshksar

@rmeshksar Did you ever figure it out?

dzg avatar Mar 06 '19 16:03 dzg