Polymorphic fields
Is your feature request related to a problem? Please describe.
Say I have the following object:
{
values: [
{type: '1', props: {.a: 1 }},
{type: '2', props: {.a: 2 }}
]
}
Right now, the only way is to define the following fields:
{
values: {
type: '!group',
subfields: {
type: {
type: 'select',
valueSources: ['value'],
fieldSettings: {
listValues: [
{ value: '1' },
{ value: '2' },
],
},
},
value: {
type: '!group',
subfields: {
a: { type: 'text', valueSources: ['value'] },
b: { type: 'text', valueSources: ['value'] },
},
},
},
},
}
Which may lead to invalid rules. If someone selects field 1 and value.b in the criteria, nothing will ever match, and it's misleading for users.
Describe the solution you'd like I would create a new property allowing a dynamic schema to be selected:
const val: Fields = {
values: {
type: '!group',
subfields: {
type: { /*...*/ },
value: {
type: '!group',
subfields: parent => {
switch (parent.field) {
case '1':
return {
a: { type: 'text', valueSources: ['value'] },
};
case '2':
return {
b: { type: 'text', valueSources: ['value'] },
};
}
},
},
},
},
};
Describe alternatives you've considered
I guess this is related to #43. The only alternative at the moment is to extract value and apply the json logic on every item in it. That removes the need for a polymorphic definition, but it's not always handy when you have multiple levels of polymorphic objects.
Additional context N/A
Plus it would be great if we had some way of changing the second element options based on the first one, for example, having a list of products for each store
