jsonforms
jsonforms copied to clipboard
Update schema atomically
Is your feature request related to a problem? Please describe.
I have two widgets on JF, something like this:
{
schema: {
type: "object",
properties: {
list: {
type: "array",
items: {
type: "string",
}
},
value: {
type: "string",
oneOf: [
{ const: "", title: "Empty"}
]
}
}
}
When i add the item into "list" i need to update oneOf of "value" with listed items.
Describe the solution you'd like
setSchemaElement(updatedSchema)
or
setSchemaElement(oldSchema => updatedSchema)
which will just update the specific item without refreshing entire form
Describe alternatives you've considered
Now i can do it for the entire schema using setSchema. This is pretty good but it rerenders the entire form and flickers the page and loses the focus as a result.
Framework
React
RendererSet
Material
Additional context
No response
Hi @tujger, setSchema is definitely the way to go. In theory it should also not lead to a rerender of the whole form. When for example the list object instance is the same in the new schema handed over to setSchema the array should not rerender.
However our React Material array renderer currently has the problem that it rerenders too much / too often. So you're probably running into this issue. The issue is pretty high on our priority list so we'll take a look eventually once the 3.0 release is finalized.
In my understanding this issue should now be gone thanks to our many rerendering improvements for JSON Forms 3.0. Updating the JSON Schema with for example lodash fp/set and handing over the new schema to JSON Forms should only rerender the appropriate parts of the form. Feel free to reopen if this is still an issue for you.