Skip to content

Checkbox error text is always hidden #127

Description

@aljchristensen

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;
}

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions