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

Label undefined for Multiselect ArrayField #2378

Closed
3 tasks done
Parnswir opened this issue May 12, 2021 · 5 comments · Fixed by #2459
Closed
3 tasks done

Label undefined for Multiselect ArrayField #2378

Parnswir opened this issue May 12, 2021 · 5 comments · Fixed by #2459

Comments

@Parnswir
Copy link
Contributor

Parnswir commented May 12, 2021

Prerequisites

JSFiddle: https://jsfiddle.net/f7xjq935/

Description

While implementing a highly customized rjsf in my current project, I use the label prop within the custom widgets to do some i18n / metadata lookup to render the widgets correctly (In essence, all forms are user-generated and the translated labels are provided by a third party). This works surprisingly fine.

However, with an array field with unique items (aka Multiselect), the label prop of the custom widget is undefined and no other prop can be used as a fallback (as far as I can see) to determine the name of the property in the schema.

I have looked into the code and noticed, that in https://github.com/rjsf-team/react-jsonschema-form/blob/master/packages/core/src/components/fields/ArrayField.js#L542, label is in fact undefined (it's not part of the ArrayField props). However, there's the name prop, which is not being used (and contains exactly what I need).

Is this a bug or expected behavior? Would it be appropriate to set label = this.props.name?

JSFiddle: https://jsfiddle.net/f7xjq935/

Steps to Reproduce

  1. Override SelectWidget with a custom component that renders the label prop
  2. Render a form with an enum field (successfully renders the label) and an array field (label = undefined)
  3. Be confused

Version

2.5.1

@Parnswir
Copy link
Contributor Author

Bump. If someone with knowledge of the internals could comment on my question, I would attempt to create a PR for this.

@epicfaace
Copy link
Member

epicfaace commented Jun 28, 2021 via email

@Parnswir
Copy link
Contributor Author

My updated jsFiddle suggests label is the key of the schema property. Other array variants use the name prop, while the multi select does not mention name and instead destructures the undefined label attribute.

To me it looks like an internal confusion of attributes at some point I cannot see right now, but to be honest, I'm not quite sure what exactly the label should be when we also have title for, well, the title of a field and name for the field's name in the schema.

@epicfaace
Copy link
Member

epicfaace commented Jul 1, 2021 via email

@Parnswir
Copy link
Contributor Author

Parnswir commented Jul 2, 2021

I've created a PR that solves the problem for me. I don't know if this has any practical implications for anyother use case though. All tests pass locally.

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.

2 participants