Hi! I’m completely new to JSONForms, and I’m trying to understand how I could implement a “dynamic dropdown”, i.e. a dropdown whose value set is determined by the value of another dropdown.
My approach so far has been to try to adapt this example Custom Renderers - JSON Forms, (which uses a MaterialBooleanControl
, along with the react-seed-app
) into one that is based on a MaterialEnumControl
, in the hope of better understanding how it works.
My test component looks like this so far (note that I had to add some dummy props that I do not fully understand yet, to satisfy TypeScript):
import {
ControlProps,
OwnPropsOfEnum,
RankedTester,
rankWith,
scopeEndsWith,
} from '@jsonforms/core';
import { withJsonFormsControlProps } from '@jsonforms/react';
import { Unwrapped } from '@jsonforms/material-renderers';
import { Grid, Typography } from '@mui/material';
const { MaterialEnumControl } = Unwrapped;
export const linkedDropdownControl = (props: ControlProps & OwnPropsOfEnum) => {
console.log(props);
return (
<Grid>
<Typography>Bla bla bla</Typography>
<MaterialEnumControl
{...props}
label='Test'
// path={'bla'}
errors={''}
t={() => 'toto'}
locale='en'
options={[
{ label: 'AA', value: 'AA' },
{ label: 'BB', value: 'BB' },
]}
data={'AA'}
/>
</Grid>
);
};
export const linkedDropdownTester: RankedTester = rankWith(
3,
scopeEndsWith('dynamic_dropdown')
);
export default withJsonFormsControlProps(linkedDropdownControl);
I also added a corresponding entry in schema.json
:
"dynamic_dropdown": {
"type": "string",
"enum": ["AA", "BB"]
}
and in uischema.json
:
{
"type": "Control",
"scope": "#/properties/dynamic_dropdown"
}
I also registered my custom renderer and tester with my <JsonForms>
. It seems to “work” (when I change the tester condition I can fall back to the custom enum renderer), but the problem is that I cannot see any MUI input being rendered (just the <Typography>
is visible).
I’m quite certain it’s just missing something quite stupid, but I searched a lot, and cannot find any more clues… any help would be much appreciated!