Hi!
I tried to implement an Enum with dynamic values. By this, I mean an Enum those options are dependent on other values of the form.
There are already some topics about that, I read some of them, but I still have issues.
Here is what I did:
In uischema:
{
"type": "Control",
"scope": "#/properties/name",
"options": {
"dynamicEnumDb": true
}
},
In schema:
"name": {
"type": "string"
},
And I have a custom render for this field:
export const DatabaseDependency = (props: ControlProps & OwnPropsOfEnum) => {
const ctx = useJsonForms();
const wholeDataObject = ctx.core?.data;
const allDatabaseNamesOptions = wholeDataObject.databases
?.map(
(db: { name: any }) => {
return { label: db.name, value: db.name } as EnumOption;
}
)
?? [];
return (
<MaterialEnumControl
{...props}
options={allDatabaseNamesOptions}
/>
);
};
export const DatabaseDependencyTester = rankWith(
3, //increase rank as needed
and(
scopeEndsWith('name'),
optionIs('dynamicEnumDb', true)
)
);
export default withJsonFormsControlProps(DatabaseDependency);
It works a little bit because the enum values are well rendered (see options={allDatabaseNamesOptions}) but the selection does not work.
When I try to select a value :
Uncaught Error: Objects are not valid as a React child (found: object with keys {name}). If you meant to render a collection of children, use an array instead.
With a already set value:
Must be string
Something is wrong between the string field and the options that are maps of value/labels.
Could you help me ?
Thanks a lot.