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

Schema defines standalone checkbox as mandatory, but asterisk is not rendered. #4136

Open
3 of 4 tasks
joe-oli opened this issue Mar 19, 2024 · 2 comments
Open
3 of 4 tasks

Comments

@joe-oli
Copy link

joe-oli commented Mar 19, 2024

Prerequisites

What theme are you using?

core

Version

5.x

Current Behavior

Making a standalone checkbox mandatory does NOT render an asterisk.
Refer to schema below in 'Steps to reproduce'

Form renders ok, errors shown up when clicking submit button, but no asterisk shows up.

Expected Behavior

Making a standalone checkbox mandatory should render an asterisk, so behavior is consistent across this package.

Steps To Reproduce

This is the schema I am using

const schema: RJSFSchema = {
    title: "User Information", //fieldset-Legend
    type: "object",
    required: ["firstName", "IAgreeCheckbox"], // These fields are mandatory;
    properties: {
      firstName: {
        title: "First Name",
        type: "string",
        minLength: 2,
        maxLength:20,
        pattern: "^[A-Za-z'-]*$"
      },
      age: {
        title: "Age",
        type: "number",
        minimum:18,
        maximum:100
      },
      //single-checkbox:
      IAgreeCheckbox: {
        type: "boolean",
        title: "I Agree with All the above",
        const: true //Must check
      }
    }
  };

/*
Field-level error message:
Must be equal to constant.

Form-level error message:
'I Agree with All the above' must be equal to constant
*/

Environment

- OS:Windows 11
- Node: v14.20.0 (not relevant)
- npm: 6.14.17 (not relevant)

Anything else?

It's a basic problem, the library should behave consistently.

@joe-oli joe-oli added bug needs triage Initial label given, to be assigned correct labels and assigned labels Mar 19, 2024
@nickgros
Copy link
Contributor

The themes where an asterisk is not shown are:

  • core (Bootstrap 3)
  • antd
  • bootstrap 4
  • chakra-ui
  • material-ui (v4)

We would accept changes that properly show the asterisk if the theme automatically supports it, but not all themes do. For example Bootstrap 3 doesn't automatically add the style, so if you were using that theme, you would be best served by adding custom CSS to your own project.

@nickgros nickgros added help wanted awaiting response and removed needs triage Initial label given, to be assigned correct labels and assigned labels Mar 22, 2024
@joe-oli
Copy link
Author

joe-oli commented Mar 26, 2024

@nickgros I fail to see how this is theme or CSS related; Before the CSS is applied, the html span with an asterisk has to be rendered?

Here is a simple example of schema to show the contrast.

{
  "title": "User Information",
  "type": "object",
  "required": [
    "checkboxGroup",
    "IAgreeCheckbox"
  ],
  "properties": {
    "checkboxGroup": {
      "title": "Checkbox Group",
      "type": "array",
      "items": {
        "type": "string",
        "enum": [
          "Option 1",
          "Option 2"
        ]
      },
      "uniqueItems": true
    },
    "IAgreeCheckbox": {
      "title": "I Agree with All the above",
      "type": "boolean",
      "const": true
    }
  }
}

The above gets rendered as follows:
Note the checkbox group, when made mandatory, renders a span with with asterisk.

<div class="form-group field field-array">
    <label class="control-label" for="root_checkboxGroup">Checkbox Group
        <span class="required">*</span>
    </label>
    <div class="checkboxes" id="root_checkboxGroup">
        <div class="checkbox ">
            <label>
                <span>
                    <input type="checkbox" id="root_checkboxGroup-0" name="root_checkboxGroup"
                        aria-describedby="root_checkboxGroup__error root_checkboxGroup__description root_checkboxGroup__help"
                        value="0">
                    <span>Option 1</span>
                </span>
            </label>
        </div>
        <div class="checkbox ">
            <label>
                <span>
                    <input type="checkbox" id="root_checkboxGroup-1" name="root_checkboxGroup"
                        aria-describedby="root_checkboxGroup__error root_checkboxGroup__description root_checkboxGroup__help"
                        value="1">
                    <span>Option 2</span>
                </span>
            </label>
        </div>
    </div>
</div>

But the single checkbox DOES NOT render a span with asterisk.

<div class="form-group field field-boolean">
    <div class="checkbox ">
        <label>
            <input type="checkbox" id="root_IAgreeCheckbox" name="root_IAgreeCheckbox" required=""
                aria-describedby="root_IAgreeCheckbox__error root_IAgreeCheckbox__description root_IAgreeCheckbox__help">
            <span>I Agree with All the above</span>
        </label>
    </div>
</div>

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