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

Default checkbox field ignores ui:title and ui:description #827

Closed
alexfiedler opened this issue Jan 30, 2018 · 8 comments · Fixed by #3533
Closed

Default checkbox field ignores ui:title and ui:description #827

alexfiedler opened this issue Jan 30, 2018 · 8 comments · Fixed by #3533

Comments

@alexfiedler
Copy link

Prerequisites

  • [x ] I have read the documentation;
  • [ x] In the case of a bug report, I understand that providing a SSCCE example is tremendously useful to the maintainers.

Description

The default checkbox field for boolean forms does not respect the ui:title or ui:description fields making it difficult to overwrite.

Steps to Reproduce

  1. Ignored UI values
    Given a schema of:
{
  "title": "Boolean Title",
  "description": "Boolean Description",
  "type": "boolean"
}

And a UI Schema of:

{
  "ui:title": "Overwrite Boolean Title",
  "ui:description": "Overwite Boolean Description"
}

Behavior

The form only displays the title from the description.

Expected behavior

It should display the ui:title and the ui:description as well.

  1. Repeated title and description

Given a schema of:

{
  "title": "Boolean Title",
  "description": "Boolean Description",
  "type": "boolean"
}

And a UI Schema of:

{
  "ui:title": "Overwrite Boolean Title",
  "ui:description": "Overwite Boolean Description",
  "ui:widget": "checkbox"
}

Behavior

The form only displays the the title, the description, the ui title, the ui description and the title.

Expected behavior

It should display only the ui:title and the ui:description.

Version

1.0.0

@epicfaace epicfaace added the bug label Jan 20, 2019
@epicfaace
Copy link
Member

Reproducible JSFiddle: https://jsfiddle.net/epicfaace/xh0uyLjn/

@CauchyAbel-zz
Copy link

This should not be hard to fix, I did encounter the same issue.

@epicfaace
Copy link
Member

@CauchyAbel it's labeled "good first issue" for a reason -- would you like to fix it? 😉

@CauchyAbel-zz
Copy link

CauchyAbel-zz commented Dec 11, 2019

I would fix it during free time since I know this is a long live issue and not that critical, LOL

I did come across this myself so I knew :) Assign to me if you could :)

@cbuv
Copy link

cbuv commented Dec 16, 2019

this issue seems to be default behavior for rjsf default boolean field

In SchemaField.js: L273 - L275

  if (schema.type === "boolean" && !uiSchema["ui:widget"]) {
    displayLabel = false;
  }

I believe adding "ui:widget":"checkbox" to uiSchema solves this issue.

@siddharths00
Copy link

Building on the answer that @cbuv wrote, I believe that just adding "ui:widget":"checkbox" to uiSchema wouldn't be enough to solve the issue. However, something along the lines of the following might help us.

if (schema.type === "boolean" && uiSchema["ui:widget"]) {
    displayLabel = false;
  }

Notice that instead of !uiSchema["ui:widget"] we have uiSchema["ui:widget, which will not display the label from Schema if we have a uiSchema label to override it. Perhaps this is all we require.

andrewcarreiro added a commit to andrewcarreiro/react-jsonschema-form that referenced this issue Aug 27, 2021
@adefrutoscasado
Copy link

Im facing this problem. Is it solved yet? Any workaround?

@heath-freenome
Copy link
Member

heath-freenome commented Feb 1, 2023

Wow, still an issue in 5.x, but it differs across the various themes. See this playground

heath-freenome added a commit to heath-freenome/react-jsonschema-form that referenced this issue Mar 22, 2023
…layed correctly

Fixes rjsf-team#827, rjsf-team#2636, rjsf-team#2399, rjsf-team#2791, rjsf-team#3231, and rjsf-team#3531 so that titles, descriptions and labels are picked up from uiSchema then schema and are hidden correctly when `label` in uiSchema is false
- Updated `@rjsf/utils` to add `displayLabel` to `WidgetProps`
- Updated `@rjsf/core` to fix the bugs as follows:
  - Updated `ArrayField`, `MultiSchemaField`, `StringField` to pass the label as `uiOptions.title || schema.title || name` as well as passing `displayLabel` from the `uiOptions`
  - Updated `ObjectField` to not pass `title` or `description` when `displayLabel` is false and `ObjectTitleTemplate` to only check `title` and `description`
  - Updated `ArrayFieldDescriptionTemplate` and `ArrayFieldTitleTemplate` to pass `globalUiOptions` into `getUiOptions` to pick up the global `label`
  - Updated `CheckboxWidget` to not show description when `displayLabel` is false
- Updated `@rjsf/antd` to fix the bugs as follows:
  - Updated `ObjectTitleTemplate` to only check `title` and `description` since they will be falsey from `ObjectField` when `displayLabel` is false
  - Updated `CheckboxWidget` to render the description using the `DescriptionFieldTemplate`, except when `displayLabel` is false
- Updated `@rjsf/bootstrap-4` to fix the bugs as follows:
  - Updated `ObjectTitleTemplate` to only check `title` and `description` since they will be falsey from `ObjectField` when `displayLabel` is false
  - Updated `CheckboxWidget` to render the description using the `DescriptionFieldTemplate`, except when `displayLabel` is false
  - Updated `RangeWidget` to only pass `label` in the `extraProps` when `displayLabel` is true
- Updated `@rjsf/chakra-ui` to fix the bugs as follows:
  - Updated `ObjectTitleTemplate` to only check `title` and `description` since they will be falsey from `ObjectField` when `displayLabel` is false
  - Updated `CheckboxWidget` to render the description using the `DescriptionFieldTemplate`, except when `displayLabel` is false
  - Updated `BaseInputTemplate`, `CheckboxesWidget`, `RadioWidget`, `RangeWidget`, `SelectWidget`, `TextareaWidget` and `UpDownWidget` to hide `label` when `displayLabel` and `label` are falsy
  - Updated test snapshots due to fixed bugs
- Updated `@rjsf/fluent-ui` to fix the bugs as follows:
  - Updated `ObjectTitleTemplate` to only check `title` and `description` since they will be falsey from `ObjectField` when `displayLabel` is false
  - Updated `CheckboxWidget` to render the description using the `DescriptionFieldTemplate`, except when `displayLabel` is false
  - Updated `BaseInputTemplate`, `CheckboxesWidget`, `ColorWidget`, `DateWidget`, `RadioWidget`, `RangeWidget`, `SelectWidget` and `UpDownWidget` to hide `label` when `displayLabel` and `label` are falsy
  - Updated `FieldTemplate` to hide description when `displayLabel` is false
  - Updated test snapshots due to fixed bugs
- Updated `@rjsf/material-ui` and `@rjsf/mui` to fix the bugs as follows:
  - Updated `ObjectTitleTemplate` to only check `title` and `description` since they will be falsey from `ObjectField` when `displayLabel` is false
  - Updated `CheckboxWidget` to render the description using the `DescriptionFieldTemplate`, except when `displayLabel` is false
  - Updated `BaseInputTemplate`, `CheckboxesWidget`, `RadioWidget`, `RangeWidget` and `SelectWidget` to hide `label` when `displayLabel` and `label` are falsy
  - Updated test snapshots due to fixed bugs
- Updated `@rjsf/semantic-ui` to fix the bugs as follows:
  - Updated `ObjectTitleTemplate` to only check `title` and `description` since they will be falsey from `ObjectField` when `displayLabel` is false
  - Updated `CheckboxWidget` to render the description using the `DescriptionFieldTemplate`, except when `displayLabel` is false
  - Updated `BaseInputTemplate`, `CheckboxesWidget`, `SelectWidget` and `TextareaWidget` to hide `label` when `displayLabel` and `label` are falsy
  - Updated test snapshots due to fixed bugs
- Updated the `widget` documentation for the new `displayLabel` prop
- Updated the `CHANGELOG.md` file accordingly
heath-freenome added a commit to heath-freenome/react-jsonschema-form that referenced this issue Mar 22, 2023
…layed correctly

Fixes rjsf-team#827, rjsf-team#2636, rjsf-team#2399, rjsf-team#2791, rjsf-team#3231, and rjsf-team#3531 so that titles, descriptions and labels are picked up from uiSchema then schema and are hidden correctly when `label` in uiSchema is false
- Updated `@rjsf/utils` to add `displayLabel` to `WidgetProps`
- Updated `@rjsf/core` to fix the bugs as follows:
  - Updated `ArrayField`, `MultiSchemaField`, `StringField` to pass the label as `uiOptions.title || schema.title || name` as well as passing `displayLabel` from the `uiOptions`
  - Updated `ObjectField` to not pass `title` or `description` when `displayLabel` is false and `ObjectTitleTemplate` to only check `title` and `description`
  - Updated `ArrayFieldDescriptionTemplate` and `ArrayFieldTitleTemplate` to pass `globalUiOptions` into `getUiOptions` to pick up the global `label`
  - Updated `CheckboxWidget` to not show description when `displayLabel` is false
- Updated `@rjsf/antd` to fix the bugs as follows:
  - Updated `ObjectTitleTemplate` to only check `title` and `description` since they will be falsey from `ObjectField` when `displayLabel` is false
  - Updated `CheckboxWidget` to render the description using the `DescriptionFieldTemplate`, except when `displayLabel` is false
- Updated `@rjsf/bootstrap-4` to fix the bugs as follows:
  - Updated `ObjectTitleTemplate` to only check `title` and `description` since they will be falsey from `ObjectField` when `displayLabel` is false
  - Updated `CheckboxWidget` to render the description using the `DescriptionFieldTemplate`, except when `displayLabel` is false
  - Updated `RangeWidget` to only pass `label` in the `extraProps` when `displayLabel` is true
- Updated `@rjsf/chakra-ui` to fix the bugs as follows:
  - Updated `ObjectTitleTemplate` to only check `title` and `description` since they will be falsey from `ObjectField` when `displayLabel` is false
  - Updated `CheckboxWidget` to render the description using the `DescriptionFieldTemplate`, except when `displayLabel` is false
  - Updated `BaseInputTemplate`, `CheckboxesWidget`, `RadioWidget`, `RangeWidget`, `SelectWidget`, `TextareaWidget` and `UpDownWidget` to hide `label` when `displayLabel` and `label` are falsy
  - Updated test snapshots due to fixed bugs
- Updated `@rjsf/fluent-ui` to fix the bugs as follows:
  - Updated `ObjectTitleTemplate` to only check `title` and `description` since they will be falsey from `ObjectField` when `displayLabel` is false
  - Updated `CheckboxWidget` to render the description using the `DescriptionFieldTemplate`, except when `displayLabel` is false
  - Updated `BaseInputTemplate`, `CheckboxesWidget`, `ColorWidget`, `DateWidget`, `RadioWidget`, `RangeWidget`, `SelectWidget` and `UpDownWidget` to hide `label` when `displayLabel` and `label` are falsy
  - Updated `FieldTemplate` to hide description when `displayLabel` is false
  - Updated test snapshots due to fixed bugs
- Updated `@rjsf/material-ui` and `@rjsf/mui` to fix the bugs as follows:
  - Updated `ObjectTitleTemplate` to only check `title` and `description` since they will be falsey from `ObjectField` when `displayLabel` is false
  - Updated `CheckboxWidget` to render the description using the `DescriptionFieldTemplate`, except when `displayLabel` is false
  - Updated `BaseInputTemplate`, `CheckboxesWidget`, `RadioWidget`, `RangeWidget` and `SelectWidget` to hide `label` when `displayLabel` and `label` are falsy
  - Updated test snapshots due to fixed bugs
- Updated `@rjsf/semantic-ui` to fix the bugs as follows:
  - Updated `ObjectTitleTemplate` to only check `title` and `description` since they will be falsey from `ObjectField` when `displayLabel` is false
  - Updated `CheckboxWidget` to render the description using the `DescriptionFieldTemplate`, except when `displayLabel` is false
  - Updated `BaseInputTemplate`, `CheckboxesWidget`, `SelectWidget` and `TextareaWidget` to hide `label` when `displayLabel` and `label` are falsy
  - Updated test snapshots due to fixed bugs
- Updated the `widget` documentation for the new `displayLabel` prop
- Updated the `CHANGELOG.md` file accordingly
heath-freenome added a commit to heath-freenome/react-jsonschema-form that referenced this issue Mar 22, 2023
…layed correctly

Fixes rjsf-team#827, rjsf-team#2636, rjsf-team#2399, rjsf-team#2791, rjsf-team#3231, and rjsf-team#3531 so that titles, descriptions and labels are picked up from uiSchema then schema and are hidden correctly when `label` in uiSchema is false
- Updated `@rjsf/utils` to add `displayLabel` to `WidgetProps`
- Updated `@rjsf/core` to fix the bugs as follows:
  - Updated `ArrayField`, `MultiSchemaField`, `StringField` to pass the label as `uiOptions.title || schema.title || name` as well as passing `displayLabel` from the `uiOptions`
  - Updated `ObjectField` to not pass `title` or `description` when `displayLabel` is false and `ObjectTitleTemplate` to only check `title` and `description`
  - Updated `ArrayFieldDescriptionTemplate` and `ArrayFieldTitleTemplate` to pass `globalUiOptions` into `getUiOptions` to pick up the global `label`
  - Updated `CheckboxWidget` to not show description when `displayLabel` is false
- Updated `@rjsf/antd` to fix the bugs as follows:
  - Updated `ObjectTitleTemplate` to only check `title` and `description` since they will be falsey from `ObjectField` when `displayLabel` is false
  - Updated `CheckboxWidget` to render the description using the `DescriptionFieldTemplate`, except when `displayLabel` is false
- Updated `@rjsf/bootstrap-4` to fix the bugs as follows:
  - Updated `ObjectTitleTemplate` to only check `title` and `description` since they will be falsey from `ObjectField` when `displayLabel` is false
  - Updated `CheckboxWidget` to render the description using the `DescriptionFieldTemplate`, except when `displayLabel` is false
  - Updated `RangeWidget` to only pass `label` in the `extraProps` when `displayLabel` is true
- Updated `@rjsf/chakra-ui` to fix the bugs as follows:
  - Updated `ObjectTitleTemplate` to only check `title` and `description` since they will be falsey from `ObjectField` when `displayLabel` is false
  - Updated `CheckboxWidget` to render the description using the `DescriptionFieldTemplate`, except when `displayLabel` is false
  - Updated `BaseInputTemplate`, `CheckboxesWidget`, `RadioWidget`, `RangeWidget`, `SelectWidget`, `TextareaWidget` and `UpDownWidget` to hide `label` when `displayLabel` and `label` are falsy
  - Updated test snapshots due to fixed bugs
- Updated `@rjsf/fluent-ui` to fix the bugs as follows:
  - Updated `ObjectTitleTemplate` to only check `title` and `description` since they will be falsey from `ObjectField` when `displayLabel` is false
  - Updated `CheckboxWidget` to render the description using the `DescriptionFieldTemplate`, except when `displayLabel` is false
  - Updated `BaseInputTemplate`, `CheckboxesWidget`, `ColorWidget`, `DateWidget`, `RadioWidget`, `RangeWidget`, `SelectWidget` and `UpDownWidget` to hide `label` when `displayLabel` and `label` are falsy
  - Updated `FieldTemplate` to hide description when `displayLabel` is false
  - Updated test snapshots due to fixed bugs
- Updated `@rjsf/material-ui` and `@rjsf/mui` to fix the bugs as follows:
  - Updated `ObjectTitleTemplate` to only check `title` and `description` since they will be falsey from `ObjectField` when `displayLabel` is false
  - Updated `CheckboxWidget` to render the description using the `DescriptionFieldTemplate`, except when `displayLabel` is false
  - Updated `BaseInputTemplate`, `CheckboxesWidget`, `RadioWidget`, `RangeWidget` and `SelectWidget` to hide `label` when `displayLabel` and `label` are falsy
  - Updated test snapshots due to fixed bugs
- Updated `@rjsf/semantic-ui` to fix the bugs as follows:
  - Updated `ObjectTitleTemplate` to only check `title` and `description` since they will be falsey from `ObjectField` when `displayLabel` is false
  - Updated `CheckboxWidget` to render the description using the `DescriptionFieldTemplate`, except when `displayLabel` is false
  - Updated `BaseInputTemplate`, `CheckboxesWidget`, `SelectWidget` and `TextareaWidget` to hide `label` when `displayLabel` and `label` are falsy
  - Updated test snapshots due to fixed bugs
- Updated the `widget` documentation for the new `displayLabel` prop
- Updated the `CHANGELOG.md` file accordingly
heath-freenome added a commit that referenced this issue Mar 24, 2023
…layed correctly (#3533)

* fix: many bugs related to titles, descriptions, labels not being displayed correctly
Fixes #827, #2636, #2399, #2791, #3231, and #3531 so that titles, descriptions and labels are picked up from uiSchema then schema and are hidden correctly when `label` in uiSchema is false
- Updated `@rjsf/utils` to add `displayLabel` to `WidgetProps`
- Updated `@rjsf/core` to fix the bugs as follows:
  - Updated `ArrayField`, `MultiSchemaField`, `StringField` to pass the label as `uiOptions.title || schema.title || name` as well as passing `displayLabel` from the `uiOptions`
  - Updated `ObjectField` to not pass `title` or `description` when `displayLabel` is false and `ObjectTitleTemplate` to only check `title` and `description`
  - Updated `ArrayFieldDescriptionTemplate` and `ArrayFieldTitleTemplate` to pass `globalUiOptions` into `getUiOptions` to pick up the global `label`
  - Updated `CheckboxWidget` to not show description when `displayLabel` is false
- Updated `@rjsf/antd` to fix the bugs as follows:
  - Updated `ObjectTitleTemplate` to only check `title` and `description` since they will be falsey from `ObjectField` when `displayLabel` is false
  - Updated `CheckboxWidget` to render the description using the `DescriptionFieldTemplate`, except when `displayLabel` is false
- Updated `@rjsf/bootstrap-4` to fix the bugs as follows:
  - Updated `ObjectTitleTemplate` to only check `title` and `description` since they will be falsey from `ObjectField` when `displayLabel` is false
  - Updated `CheckboxWidget` to render the description using the `DescriptionFieldTemplate`, except when `displayLabel` is false
  - Updated `RangeWidget` to only pass `label` in the `extraProps` when `displayLabel` is true
- Updated `@rjsf/chakra-ui` to fix the bugs as follows:
  - Updated `ObjectTitleTemplate` to only check `title` and `description` since they will be falsey from `ObjectField` when `displayLabel` is false
  - Updated `CheckboxWidget` to render the description using the `DescriptionFieldTemplate`, except when `displayLabel` is false
  - Updated `BaseInputTemplate`, `CheckboxesWidget`, `RadioWidget`, `RangeWidget`, `SelectWidget`, `TextareaWidget` and `UpDownWidget` to hide `label` when `displayLabel` and `label` are falsy
  - Updated test snapshots due to fixed bugs
- Updated `@rjsf/fluent-ui` to fix the bugs as follows:
  - Updated `ObjectTitleTemplate` to only check `title` and `description` since they will be falsey from `ObjectField` when `displayLabel` is false
  - Updated `CheckboxWidget` to render the description using the `DescriptionFieldTemplate`, except when `displayLabel` is false
  - Updated `BaseInputTemplate`, `CheckboxesWidget`, `ColorWidget`, `DateWidget`, `RadioWidget`, `RangeWidget`, `SelectWidget` and `UpDownWidget` to hide `label` when `displayLabel` and `label` are falsy
  - Updated `FieldTemplate` to hide description when `displayLabel` is false
  - Updated test snapshots due to fixed bugs
- Updated `@rjsf/material-ui` and `@rjsf/mui` to fix the bugs as follows:
  - Updated `ObjectTitleTemplate` to only check `title` and `description` since they will be falsey from `ObjectField` when `displayLabel` is false
  - Updated `CheckboxWidget` to render the description using the `DescriptionFieldTemplate`, except when `displayLabel` is false
  - Updated `BaseInputTemplate`, `CheckboxesWidget`, `RadioWidget`, `RangeWidget` and `SelectWidget` to hide `label` when `displayLabel` and `label` are falsy
  - Updated test snapshots due to fixed bugs
- Updated `@rjsf/semantic-ui` to fix the bugs as follows:
  - Updated `ObjectTitleTemplate` to only check `title` and `description` since they will be falsey from `ObjectField` when `displayLabel` is false
  - Updated `CheckboxWidget` to render the description using the `DescriptionFieldTemplate`, except when `displayLabel` is false
  - Updated `BaseInputTemplate`, `CheckboxesWidget`, `SelectWidget` and `TextareaWidget` to hide `label` when `displayLabel` and `label` are falsy
  - Updated test snapshots due to fixed bugs
- Updated the `widget` documentation for the new `displayLabel` prop
- Updated the `CHANGELOG.md` file accordingly

* - Added a new `labelValue()` function to `@rjsf/utils`
- Updated all ui packages to use `labelValue()` as appropriate, in some cases replacing the `schema.title` with `undefined` which is the real value of `schema.title` when label is an empty string
- Added a new `FluentLabel` component by refactoring common code out of `CheckboxesWidget`, `ColorWidget`, `RangeWidget` and `UpDownWidget`

* - Missed one `labelValue()` usage

* Apply suggestions from code review

Fix bug links
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment