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

Custom widget for array always shows label #3820

Open
4 tasks done
doronrosenberg opened this issue Aug 11, 2023 · 9 comments
Open
4 tasks done

Custom widget for array always shows label #3820

doronrosenberg opened this issue Aug 11, 2023 · 9 comments
Labels

Comments

@doronrosenberg
Copy link

Prerequisites

What theme are you using?

core

Version

5.x

Current Behavior

Using a custom widget set via ui:schema for an array field, the label is being rendered by rjsf even if the label is disabled in ui:schema. If I remove the custom widget, the label is properly hidden, so seems to be an issue with custom widgets for array types.

See See https://codesandbox.io/s/rough-bird-f7yf2k for a simple reproduction.

Note that A list of strings, the label for the field, is still showing.

From reading the documentation, this should be the correct way to hide the labels, and it works for non-array overrides.

Expected Behavior

If I override the rendering of a type using my custom widget, I would expect to be in full control and be able to hide everything related to the field I am taking over. Its part of what makes rjsf so powerful with the ui:schema.

Steps To Reproduce

See https://codesandbox.io/s/rough-bird-f7yf2k.

Environment

No response

Anything else?

Thanks!

@doronrosenberg doronrosenberg added bug needs triage Initial label given, to be assigned correct labels and assigned labels Aug 11, 2023
@heath-freenome
Copy link
Member

What are you trying to do with the widget and the array field. Perhaps you can override one of the Array-based templates instead?

@heath-freenome heath-freenome added question and removed bug needs triage Initial label given, to be assigned correct labels and assigned labels Aug 11, 2023
@doronrosenberg
Copy link
Author

The requirement is to have a grid/table based editor for certain array types. Since we are using a third party grid library, using the templates would likely not work too well since the grid wants to handle the rendering itself.

The use of custom ui:widget here works perfectly for us, its just that the label for the field always renders which seems like a bug to me. If you agree that it should be hidden and can point at roughly where the code for this is, I could take a stab at a pr for this.

@heath-freenome
Copy link
Member

It should be being hidden by the FieldTemplate or maybe something in your implementation is using the TitleFieldTemplate and you need to call the schemaField.getDisplayLabel() function yourself?

@doronrosenberg
Copy link
Author

doronrosenberg commented Aug 11, 2023

Per the reproduction at https://codesandbox.io/s/rough-bird-f7yf2k, you can see that using a ui:widget to override a field and using ui:options to hide the label doesn't work. Not using templates at all, just purley overriding it using ui:widget

@heath-freenome
Copy link
Member

@doronrosenberg I was pointing you in the direction of the code

@doronrosenberg
Copy link
Author

My bad! The issue is indeed that getDisplayLabel() is returning true in this case, will take a look to see why.

btw, https://rjsf-team.github.io/react-jsonschema-form/docs/contributing#development-server says you need to restart the dev server when making changes, but vite is using HMR to update the code on the fly as I make changes.

@doronrosenberg
Copy link
Author

There are two questions I have on fixing this:

First, in https://github.com/rjsf-team/react-jsonschema-form/blob/main/packages/utils/src/schema/getDisplayLabel.ts#L37 the default value for showing the label is read from ui:schema but then depending on the schema that value can be overriden. I understood ui:schema as being the override, so if label is set to false it should just return false immediately instead of doing the schema checks.

The second way to fix it is this if statement(https://github.com/rjsf-team/react-jsonschema-form/blob/main/packages/utils/src/schema/getDisplayLabel.ts#L46), where if we have a customWidget we will always show the label. If a custom widget is present, the label should probably be hidden.

|| isCustomWidget(uiSchema);

becomes:

&& !isCustomWidget(uiSchema);

To me it looks like there are two bugs here (ui:schema not being the final override, custom array widgets result in label being shown), but defer to what you would consider the correct fix.

@heath-freenome
Copy link
Member

I would say, if uiOptions.label is false, exit immediately.

@Deep-z21
Copy link

Hey @doronrosenberg I am also working on making a tabular UI for array items. So, like if there are 5 entries in an array then it should get represented in a tabular way. But I am not able to find a correct approach because firstly, I thought of overriding ArrayFieldItemTemplate but then problem was that whole aggregate formData is not coming at once, its coming to template item wise. Any solutions ?

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

3 participants