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

Modify JSON Validation for Optgroup support #1813

Closed
Enola-guy opened this issue Jun 14, 2020 · 7 comments · May be fixed by #4374
Closed

Modify JSON Validation for Optgroup support #1813

Enola-guy opened this issue Jun 14, 2020 · 7 comments · May be fixed by #4374

Comments

@Enola-guy
Copy link

Hello, I've successfully created the widget to support optgroup select (i.e. categories inside a select). I'm now seeking help for the validation.

In order to generate the categories I give a dict instead of a list to my "enum" field. How can I modify the JSON validation to avoid the error .enum should be array

Here is the codepen of my implementation:
https://codepen.io/enola-guy/pen/ZEQOVEN

If you can explain me the steps missing, I would gladly open a PR in order to make this feature in the main branch :)

image

@epicfaace
Copy link
Member

@Enola-guy thanks for your custom widget! I don't think we can merge this into the main library, though, until we have a JSON Schema-compliant approach (and in JSON Schema, enum must be an array, not a dict). Can you think of a JSON-schema-compliant way of using optgroups? For example, this might involve customizing the optgroups in uiSchema using something like this:

{
    "ui:groups": [
         { "title": "Theropods", "items": ["Tyrannosaurus", "Velociraptor"] },
         ...
     ]
}

This is just an idea -- let me know if you have any other thoughts / ways of doing this.

@Enola-guy
Copy link
Author

Thanks for the hint, I'm gonna try this, unfortunately it's not going to be DRY, but that's something. Will update the code today.

@Enola-guy
Copy link
Author

Hey late update, thank you so much it worked ui:groups did the work ! @epicfaace

@epicfaace
Copy link
Member

Would you be interested in contributing your widget to this library as a PR?

@Enola-guy
Copy link
Author

Enola-guy commented Jul 7, 2020

I would be very interested ! I just need to know precisely what needs to be done, I'm more of a python dev than a react one.

@vladyslavarkavenko
Copy link

@Enola-guy Can you please share your working code here?

@nagaozen
Copy link

nagaozen commented Nov 11, 2024

I made a PR implementing this feature:

image

It extends the current SelectWidget to support optgroups at ui:options. e.g.:

  "selectWidgetOptions3": {
    "ui:options": {
      "optgroups": {
        "lipsum": [
          "foo"
        ],
        "dolorem": [
          "bar"
        ]
      }
    }
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants