Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use uiSchema to customize oneOf/anyOf with different types #1141

Closed
2 tasks done
epicfaace opened this issue Jan 20, 2019 · 5 comments
Closed
2 tasks done

Use uiSchema to customize oneOf/anyOf with different types #1141

epicfaace opened this issue Jan 20, 2019 · 5 comments
Labels

Comments

@epicfaace
Copy link
Member

epicfaace commented Jan 20, 2019

Prerequisites

  • I have read the documentation;
  • In the case of a bug report, I understand that providing a SSCCE example is tremendously useful to the maintainers.

Description

I would like to use oneOf with different types. (another way of solving the problem in issue #282)

Steps to Reproduce

Use this schema:

{
  "type": "object",
  "properties": {
    "name": {
      "oneOf": [
        {
          "type": "string"
        },
        {
          "type": "number"
        }
      ]
    }
  }
}

Playground link

Expected behavior

Want to be able to select different types.

Actual behavior

I get this:
image

Version

1.2.0

@LucianBuzzo
Copy link
Collaborator

@epicfaace If you input a value you'll notice that it is coerced into a number or string depending on the option you selected. By default this module uses a "text" input to render number fields, which is why it looks like there is no change.
Normally you'd be able to use UISchema to change the widget used (for example to change it to a range or number input), however this doesn't currently work with anyOf/oneOf.

@loganvolkers
Copy link
Contributor

Normally you'd be able to use UISchema to change the widget used (for example to change it to a range or number input), however this doesn't currently work with anyOf/oneOf.

That sounds like something worth fixing

@epicfaace epicfaace changed the title Support oneOf with different types Use uiSchema to customize oneOf with different types Jan 22, 2019
@epicfaace epicfaace added bug and removed enhancement labels Jan 22, 2019
@acronymhaterheidi
Copy link

I have encountered nearly the same issue in that I would like to use oneOf with an object and a basic type. I also want to use this oneOf inside an array. The oneOf works differently inside and outside of an array.

Here is the oneOf schema by itself:

{
  "oneOf": [
    {
      "type": "integer"
    },
    {
      "type": "object",
      "properties": {
        "elt1": {
          "type": "integer"
        },
        "elt2": {
          "type": "string"
        }
      },
      "required": [
        "elt1",
        "elt2"
      ]
    }
  ]
}

With a playground link.

This works fairly well although it is a little glitchy.

And the same schema within an array:

{
  "type": "object",
  "properties": {
    "myArray": {
      "type": "array",
      "items": {
        "oneOf": [
          {
            "type": "integer"
          },
          {
            "type": "object",
            "properties": {
              "elt1": {
                "type": "integer"
              },
              "elt2": {
                "type": "string"
              }
            },
            "required": [
              "elt1",
              "elt2"
            ]
          }
        ]
      }
    }
  }
}

With a playground link

This displays completely different behavior from the previous schema and does not allow input for the second option.

@LucianBuzzo
Copy link
Collaborator

@Rasstrelnikov Since you have reported a separate problem, I've opened a new issue to track it #1168

@epicfaace epicfaace changed the title Use uiSchema to customize oneOf with different types Use uiSchema to customize oneOf/anyOf with different types Mar 16, 2019
@stale
Copy link

stale bot commented Apr 15, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please leave a comment if this is still an issue for you. Thank you.

@stale stale bot added the wontfix label Apr 15, 2022
@stale stale bot closed this as completed May 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants