koumoul-dev / vuetify-jsonschema-form

Create beautiful and low-effort forms that output valid data. Published on npm as @koumoul/vjsf.
https://koumoul-dev.github.io/vuetify-jsonschema-form/latest/
MIT License
546 stars 155 forks source link

How to refer to the data in the context through another form item? #297

Closed cheezone closed 1 month ago

cheezone commented 3 years ago
context={
brands:[ {
                                title: 'Xiaomi',
                                value: 'Xiaomi',
                                brands: ['Xiaomi', 'Redmi', 'BS', 'POCO'],
                            },
                            {
                                title: 'Huawei',
                                value: 'Huawei',
                                brands: ['Huawei', 'Honor'],
                            },]
}

...

designedBy: {
                                    title: 'designedBy',
                                    type: 'string',
                                    'x-fromData': 'context.brands',
                                    'x-itemTitle': 'title',
                                    'x-itemKey': 'value',
                                },
                                dependencies: {
                                    designedBy: {
                                        brand: {
                                            type: 'string',
                                            title: 'brand',
                                            'x-fromData':
                                                'context.brands[designedBy].brands',
                                        },
                                    },
                                },

When select "Xiaomi", Should show ['Xiaomi', 'Redmi', 'BS', 'POCO']. But it doesn't work

albanm commented 3 years ago

For now this is not supported, the expression in x-fromData is a simple getter not a complete expression. I am working on using dynamically created JS functions to handle more complete expressions that could combine data from the context and the model, it should be available in 1 or 2 days. But this functionality will be activated using an option with a strong warning, to use it you will have to have complete trust in the source of the json schema (not a problem in most cases as the source of the schema is the same as the code source of the application itself, but not always the case).

cheezone commented 3 years ago

Thank!

albanm commented 3 years ago

please have a look here and here

cheezone commented 3 years ago

Okay, I will go to see it, thank you for your work!