You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On a oneOf schema that contains a handful of objects that might slightly differ, the selectedOption state is immediately corrupted and the selected option changes once editing data within the form.
Debugging, the problem is the componentDidUpdate React event handler on the MultiSchemaField component. This event is invoked anytime formData is changed within the multi schema, and is changing the selectedOption without the users permission, resulting in an incredibly degraded experience on these types of schemas. Check out this playground example for an example of it in action.
Completely eliminating the componentDidUpdate event from this component resolves the issue, but I'm having a hard time understanding why this component has a componentDidUpdate at all to reset the selectedOption when formData changes. selectedOption should only change with the onOptionChange event handler, no?
to emphasize: it happens only if formData matches multiple types from same oneOf simultaneously
why it can re-calculate type after formData has changed? Since formData is coming from outside, it's technically possible new data does not match shape of previously selected "oneOf". Maybe a desired result would be not picking first matching type but checking, if data still fits type currently selected. And then picking first matching only if data shape does not satisfy type currently selected.
By now, in general case, I see 2 different approaches with their own pitfalls:
to convert flat list of "oneOf" into a tree of nested "oneOf" where at each level there would have be unique set of fields. Easier to say than to do, sure.
to materialize type with introducing extra field with "enum" of only one possible value("enum": ["Cuba"]), enforce that value with "default": ["Cuba"] and hide it with "ui:widget": "hidden" in UI schema(example). Unfortunately, in this case we need also trim that extra field before sending to server.
Prerequisites
Description
On a
oneOf
schema that contains a handful of objects that might slightly differ, theselectedOption
state is immediately corrupted and the selected option changes once editing data within the form.Debugging, the problem is the
componentDidUpdate
React event handler on theMultiSchemaField
component. This event is invoked anytimeformData
is changed within the multi schema, and is changing theselectedOption
without the users permission, resulting in an incredibly degraded experience on these types of schemas. Check out this playground example for an example of it in action.Completely eliminating the
componentDidUpdate
event from this component resolves the issue, but I'm having a hard time understanding why this component has acomponentDidUpdate
at all to reset theselectedOption
whenformData
changes.selectedOption
should only change with theonOptionChange
event handler, no?Steps to Reproduce
1
into thelisting_id
input.Expected behavior
The selected
MultiSchemaField
should not change unless the user invokes a change to the dropdown.Actual behavior
MultiSchemaField
selectedOption
state is changed whenformData
is updated.Version
This is happening on the latest master.
The text was updated successfully, but these errors were encountered: