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

Does ui:widget work for type: "object"? #4464

Open
1 task done
ferretwithaberet opened this issue Jan 23, 2025 · 1 comment
Open
1 task done

Does ui:widget work for type: "object"? #4464

ferretwithaberet opened this issue Jan 23, 2025 · 1 comment

Comments

@ferretwithaberet
Copy link

ferretwithaberet commented Jan 23, 2025

Prerequisites

What theme are you using?

antd

What is your question?

I am trying to make a widget for Ant Pro Flow.
It's input data is an object of form:

type ProFlowInput = {
  nodes: Node[];
  edges: Edge[];
}

I tried to define it as

{
  // ...
  "my_flow": {
    "type": "object",
    "properties": {
      "nodes": {
        "type": "array",
        "items": {
          "type": "object"
        }
      },
      "edges": {
        "type": "array",
        "items": {
          "type": "object"
        }
      }
    }
  }
  // ...
}

in my schema and

{
  // ...
  "my_flow": {
    "ui:title": "Some flow",
    "ui:widget": "ant-flow"
  }
  // ...
}

in my uiSchema.

But this does not seem to apply at all. Is there anything I am missing?

Edit: Ok, I noticed that custom widgets cannot be applied to the object type. But, is there anything I could do to workaround this?

Edit 2: In case anyone else runs into this, you can use type: "array" and do something like

const { value } = props
const [nodes = [], edges = []] = value ?? []
@ferretwithaberet ferretwithaberet added needs triage Initial label given, to be assigned correct labels and assigned question labels Jan 23, 2025
@nickgros
Copy link
Contributor

@ferretwithaberet Could you perhaps provide a custom ObjectField?

The idea is that RJSF has no idea what fields an object may contain, so the base fields and templates just delegate that logic to widgets. Since you have a very specific idea of what your object will look like, and how the UI should behave, you can override the entire field with the UI/logic you need.

You can wrap our base ObjectField, or use the core implementation as a starting point for your custom component.

@nickgros nickgros added awaiting response and removed needs triage Initial label given, to be assigned correct labels and assigned labels Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants