Search code examples
csstwitter-bootstrapbootstrap-4

Force to show invalid-feedback in Bootstrap 4


Let's say I have HTML like this:

...
<div class="form-group">
    <div class="form-check">
        <input class="form-check-input" type="checkbox" id="invalidCheck">
        <label class="form-check-label" for="invalidCheck">
            Agree to something
        </label>
    </div>

    <div class="invalid-feedback">
        I am outside of `form-check`!
    </div>
</div>
...

I want to force to show the <div class="invalid-feedback">... without using JavaScript (want to use Bootstrap CSS only). And I know I can use CSS classes like was-validated or is-invalid, but invalid-feedback is outside of form-check. Is there an easy and simple way to show invalid-feedback by adding Bootstrap related CSS classes?

I found one solution:

<div class="invalid-feedback d-block">
    Now I am visible!
</div>

But I feel like it's a hacky solution. Please advise!


Solution

  • Use display classes to display it manually for example d-block

    use it like so

    <div class="valid-feedback d-block"> 
    

    or

    <div class="invalid-feedback d-block">
    

    Find more in documentation