Closed
Description
Is your feature request related to a problem? Please describe.
I am trying now implement the delete button functionality for the ArrayControl
in the Vanilla Renderer. But this seems to be more difficult as expected.
Describe the solution you'd like
My most naive approach was to simple add delete button around the JsonFormsDispatch
:
...
return (
<div><JsonFormsDispatch
schema={schema}
uischema={childUiSchema || uischema}
path={childPath}
key={childPath}
renderers={renderers}
/><button
aria-label={`Delete`}
onClick={() => {
if (window.confirm('Are you sure you wish to delete this item?')) {
data.splice(index, 1);
}
}}>Delete</button></div>
);
...
Technical this works, but the component is not rerendered.
Describe alternatives you've considered
The TableArrayControl
instead used an method removeItems
wrapped by a method confirmDelete
confirmDelete = (path: string, index: number) => {
const p = path.substring(0, path.lastIndexOf(('.')));
this.props.removeItems(p, [index])();
};
The button triggers this method:
<button
aria-label={`Delete`}
onClick={() => {
if (window.confirm('Are you sure you wish to delete this item?')) {
this.confirmDelete(childPath, index);
}
}}
>
Delete
</button>
I tried to use somehow the removeItems
method but I did not succeed because of the missing props. At least I did not find out how to build a similar variable in the ArrayControl
.
Can you please give me a hint what the correct approach would be so that I can prepare a pull request.
Framework
React
RendererSet
Vanilla
Additional context
No response