Hi!
We are currently testing the new 3.0.0 release, especially the new prop additionalErrors
.
We understood that it can be used to gather and merge errors for example from the APIs, or in general external ones, but we were wondering if it suits also updates coming from within the form itself.
Can I use it in a custom Renderer of mine instead of updateErrors
, if I want to manage some additional ones?
The way I manage to make it work was providing a state and its setter outside JsonForm, providing both via Provider and managing the errors inside each interested Renderer.
const [additionalErrors, setAdditionalErrors] = useState<ErrorObject[]>([]);
return (
<JsonFormsAdditionalErrorsProvider value={{ additionalErrors, setAdditionalErrors }}>
<JsonForms
[....]
additionalErrors={additionalErrors}
/>
</JsonFormsAdditionalErrorsProvider>
The problem arise when I try to apply both the value change and the validation, which I currently do as follows:
const onChange = (path: string, value: any) => {
handleChange(path, value);
setAdditionalErrors(getAdditionalErrors());
};
where setAdditionalErrors
is the state setter coming from the Provider, and getAdditionalErrors
derives the errors from the original, after the evaluation.
The effect is that the value update is not correctly seen by JsonForm, and I have to wrap it in a setTimeout to make it work:
const onChange = (path: string, value: any) => {
handleChange(path, value);
setTimeout(() => setAdditionalErrors(getAdditionalErrors()), 200);
};
So I’m wondering if I’m correctly using additionalErrors or maybe it’s not meant to be used inside my Renderers.
In general, with this new version what is the suggested way to manage custom error validation from Renderers and Cells, when you cannot rely on the json schema only?
Could you advise please? Thanks