Hello,
I’d like to add a button to each entry of an array field. Let’s assume my data looks like:
"name": "Customer Order",
"payments": [
{
"status": "paid",
"amount": 322
},
{
"status": "unpaid",
"amount": 100
}
]
and json schema is:
{
"type": "object",
"properties": {
"name": {
"type": "string",
"minLength": 1
},
"payments": {
"type": "array",
"items": {
"type": "object",
"properties": {
"status": { "type": "string" },
"amount": { "type": "number" }
}
}
}
},
"required": ["name"]
}
I’d like to add an action button on each rendered item. Could you guide me on how to achieve that?
Btw. I managed to add a custom button on objects that are not array items. I did that by following your example with adding a field to schema.json (Custom Renderers - JSON Forms) and implementing a tester that would check on the existence of custom fields in the json schema:
export function buttonTesterFactory({rank=3, action=undefined}) {
return rankWith(
rank, //increase rank as needed
schemaMatches((schema) => {
return schema.form?.type === "button" && (action && action === schema.form?.action)
}
)
)
}
and renderer:
const {buttonLabel, onClick, isLoading} = props
return (
<Grid container>
<Grid item xs={12}>
<LoadingButton
sx={{marginBottom: '1rem'}}
variant="contained"
onClick={onClick}
loading={isLoading}
>
{buttonLabel}
</LoadingButton>
</Grid>
</Grid>
);
};
but when trying to do the same for object being array item, it seems like the tester isn’t being matched. Is there a way to implement a tester to match objects being array items? (or maybe this can be achieved using uischema?)