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

Checkbox error text is always hidden #127

Open
aljchristensen opened this issue Mar 10, 2020 · 1 comment
Open

Checkbox error text is always hidden #127

aljchristensen opened this issue Mar 10, 2020 · 1 comment

Comments

@aljchristensen
Copy link

Because of the way the Bootstrap style rules are set up, the way checkbox elements are currently structured results in the associated error text remaining hidden.

Right now, the resulting HTML structure when a checkbox form element has an associated error is:

<div class="form-group has-danger">
  <div class="custom-control custom-checkbox">
      <input type="checkbox" id="check" class="custom-control-input is-invalid">
      <label class="custom-control-label" for="check">Label text</label>
  </div>
  <div id="check_error_0" class="invalid-feedback">Error text</div>
</div>

but it needs to be

<div class="form-group has-danger">
  <div class="custom-control custom-checkbox">
      <input type="checkbox" id="check" class="custom-control-input is-invalid">
      <label class="custom-control-label" for="check">Label text</label>
      <div id="check_error_0" class="invalid-feedback">Error text</div>
  </div>
</div>

That is, the invalid-feedback div needs to be a subsequent sibling of the is-invalid input.

The relevant Bootstrap rules are

.invalid-feedback {
  display: none;
  ...
}

.was-validated :invalid ~ .invalid-feedback,
.was-validated :invalid ~ .invalid-tooltip,
.is-invalid ~ .invalid-feedback,
.is-invalid ~ .invalid-tooltip {
  display: block;
}
@adrianhurt
Copy link
Owner

Sorry @aljchristensen for the delay. I know it's too late, but at least the response is here 😓

You're right, I should document this known issue. The problem here is the library tries to have a consistent structure for the majority of the cases. The field constructor is who is charge of handling validations, feedback and helpers. And in that case the input itself is wrapped by a div, so this HTML is rendered.

So you need to make your own CSS hack using class .has-danger. In deed, that's one of the reasons I added has-* at form-group level. So you could try with something like:

.has-danger .invalid-feedback,
.has-danger .invalid-tooltip,
.has-success .valid-feedback,
.has-success .valid-tooltip {
    display: block;
}

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

No branches or pull requests

2 participants