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

No hint on radiobuttons when required #306

Open
bluepuma77 opened this issue Dec 13, 2020 · 3 comments
Open

No hint on radiobuttons when required #306

bluepuma77 opened this issue Dec 13, 2020 · 3 comments
Labels

Comments

@bluepuma77
Copy link

When using required=true on type radiobuttons the browser does not show a hint and does not prevent submitting.

Instead a jsonform error is created. I would expect a hint and that it does not submit until a selection is taken.

How to reproduce:

  1. I have 3 fields: text, radiobuttons, birthdate

jsonform-radiobuttons-1

{
    "schema": {
        "name": {
            "title": "Name",
            "type": "string",
            "required": true
        },
        "birthdate": {
            "type": "string",
            "title": "Birth date",
            "required": true
        },
        "q1": {
            "type": "string",
            "title": "Question",
            "enum": [
                "yes",
                "no"
            ],
            "required": true
        }
    },
    "form": [
        {
            "key": "name",
            "type": "text"
        },
        {
            "key": "q1",
            "type": "radiobuttons",
            "activeClass": "btn-success"
        },
        {
            "key": "birthdate",
            "type": "date"
        },
        {
            "type": "submit",
            "title": "Submit"
        }
    ]
}
  1. When submitting empty, only field 1 and 3 are marked, field 1 gets a hint. Required field 2 is ignored.

jsonform-radiobuttons-2

  1. When field 1 is filled, only field 3 is marked and gets a hint. Required field 2 is ignored.

jsonform-radiobuttons-3

  1. When field 1 and 3 are filled, I can submit the form and receive a jsonform error.

jsonform-radiobuttons-4

Using jquery-3.5.1, bootstrap v4.4.1 and latest underscore.js and jsonform.js, jsv.js from jsonform repo.

    <script src="/static/js/jquery-3.5.1.min.js" ></script>
    <script src="/static/js/bootstrap.bundle.min.js"></script>
    <script src='/static/js/underscore-min.js'></script>
    <script src='/static/js/jsv.js'></script>
    <script src='/static/js/jsonform.js'></script>

<style>
    .jsonform-required>label:after {
        content: ' *';
        color: red;
    }
    .btn-default {
        color: #343a40;
        background-color: transparent;
        background-image: none;
        border-color: #343a40;
    }
</style>
@bluepuma77
Copy link
Author

Some steps forward. I figured out that I need a CSS class to display the error with the radiobuttons.

    .error {
        border: 2px solid red;
        border-radius: .25rem;
    }

The hint is only displayed when the other fields are correctly filled out. And it still creates a jsonform error, where the others do not.

jsonform-radiobuttons-5

jsonform-radiobuttons-6

@bluepuma77
Copy link
Author

Funny, the activeClass is used on the header above the buttons when you click it. Test it in the official demo.

@tchapi tchapi added the Bug label Dec 14, 2020
@tchapi
Copy link
Member

tchapi commented Dec 14, 2020

Hi @bluepuma77

Thanks for your report. I'm not entirely sure why this happens but I think it may be related to input group validation on the bootstrap side (https://getbootstrap.com/docs/4.5/components/forms/#validation); What do you think ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants