Skip to content

Modify JSON Validation for Optgroup support #1813

Closed
@Enola-guy

Description

@Enola-guy

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

Activity

epicfaace

epicfaace commented on Jun 14, 2020

@epicfaace
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

Enola-guy commented on Jun 15, 2020

@Enola-guy
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

Enola-guy commented on Jul 4, 2020

@Enola-guy
Author

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

epicfaace

epicfaace commented on Jul 4, 2020

@epicfaace
Member

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

Enola-guy

Enola-guy commented on Jul 7, 2020

@Enola-guy
Author

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

vladyslavarkavenko commented on Jul 10, 2020

@vladyslavarkavenko

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

nagaozen

nagaozen commented on Nov 11, 2024

@nagaozen

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @nagaozen@epicfaace@Enola-guy@vladyslavarkavenko

      Issue actions

        Modify JSON Validation for Optgroup support · Issue #1813 · rjsf-team/react-jsonschema-form