Skip to content

Vue Vanilla OneOf renderer fails to properly switch between boolean and array values #2506

@SilentArctic

Description

@SilentArctic

Describe the bug

Given the following JSON schema, if the user sets a boolean value then switches the oneOf control to the array schema and adds an array item, the error TypeError: array.push is not a function is given.

{
  "oneOf": [
    {
      "title": "Boolean",
      "type": "boolean"
    },
    {
      "title": "Array",
      "type": "array",
        "items": {
        "type": "string"
      }
    }
  ]
}

Expected behavior

The stored value should be reset and turned into an array so items can be added.

Steps to reproduce the issue

  1. Setup an app with @jsonforms/vue-vanilla renderers
  2. Supply the schema listed in the description above
  3. Set an array value
  4. Set a boolean value (notice the prompt to clear the data)
  5. Set an array value (notice there is no prompt to clear the data)
  6. Add an array item (notice the form does not change and an error is now present in the console)

Note: I don't think there needs to be prompt when switching away from a boolean value, but the data should be cleared.

Screenshots

No response

Which Version of JSON Forms are you using?

3.6.0

Package

Vue Vanilla Renderers

Additional context

I've recreated a OneOfRenderer component and found the issue can be resolved by the following change. It will need more in-depth testing, but this works for me.

// wrap useJsonFormOneOfControl with useVanillaControl
const input = useVanillaControl(useJsonFormsOneOfControl(props as ControlProps));
...
return {
  // remove useVanillaControl wrapper from the returned input
  ...input,
  ...
}

Metadata

Metadata

Assignees

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions