Bootstrap 4 invalid feedback with input group not displaying

前端 未结 10 969
遇见更好的自我
遇见更好的自我 2021-02-04 00:38

I have been looking into Bootstrap 4 - beta, however when using .is-invalid with .input-group it doesn\'t seem to show up.

相关标签:
10条回答
  • 2021-02-04 01:03

    You can always override styles using !important Add this to your custom css file

    .invalid-feedback{
        display: inline !important;
    }
    
    0 讨论(0)
  • 2021-02-04 01:05

    To make it looks exactly the same you can use an inline if, in Laravel for example:

    <input name="label" class="{{$errors->has('label') ? 'is-invalid' : '' }}">
                       @if ($errors->has('label'))
                           <div class="text-danger" role="alert">
                              <small>{{ $errors->first('code') }}</small>
                            </div>
                       @endif
    
    0 讨论(0)
  • 2021-02-04 01:06

    The way Bootstrap does override the display from none to block is by checking first for a previous is-invalid class, for example! Check this CSS out:

    That means, in case of an error, first is-invalid must be applied on an element and then invalid-feedback on another afterward! Like the following in Laravel, for instance:

    {{-- Either following an input --}}
    
    <input type="password" id="registerPassword"
           class="form-control @error('register_password') is-invalid @enderror"
           name="register_password" required autocomplete="new-password"
    >
    
    @error('register_password')
        <span class="invalid-feedback" role="alert">
            <strong>{{ $message }}</strong>
        </span>
    @enderror
    
    {{-- Or separately in DOM --}}
    
    @error('register_password')
        <div class="is-invalid">...</div>
    
        <span class="invalid-feedback" role="alert">
            <strong>{{ $message }}</strong>
        </span>
    @enderror
    
    0 讨论(0)
  • 2021-02-04 01:11

    Boostrap 4 is very buggy. My suggestion is to replace:

     <div class="invalid-feedback">
     Text here
     </div>
    

    With:

    <div class="text-danger">
    Text here
    </div>
    

    And the second one looks virtually the same and will not fail.

    For a better look, try:

    <div class="text-danger">
    <small>Text here</small>
    </div>
    
    0 讨论(0)
  • 2021-02-04 01:14

    I found this solution

    <div class="input-group ">
        <div class="input-group-prepend">
            <div class="input-group-text">Start Date</div>
        </div>
        <input type="text" class="form-control is-invalid" placeholder="Date Input">
        <div class="invalid-feedback order-last ">
            Error Message
        </div>
        <div class="input-group-append">
            <div class="input-group-text"><i class="fa fa-calendar"></i></div>
        </div>
    </div>
    
    0 讨论(0)
  • 2021-02-04 01:19

    They haven't taken into account their own examples using input group addons and buttons, even with a column model. The markup does only facilitate "neighboring" elements, not parent > neighboring element (there is no CSS rule for that).

    It seems, for now, you should fall back to Alpha 6 or program your own CSS classes accordingly. I've done the same, unfortunately.

    Please note when reading my answer that this was posted just as the beta was released. :)

    0 讨论(0)
提交回复
热议问题