Bootstrap 4.0 invalid-feedback doesn't show

。_饼干妹妹 提交于 2019-12-22 10:46:13

问题


I am using the Bootstrap 4.0 (non-beta) validation and have a problem to display the invalid-feedback text.

<div class="form-row">
  <label class="form-control-label">Name:</label>
  <div class="col-4">
    <input class="form-control is-invalid" min="0" type="number"/>
  </div>
    <div class="col-4">
    <div class="invalid-feedback">
    Invalid Feedback Text
    </div>
  </div>
</div>

In the above example the text "Invalid Feedback Text" is not displayed.

The reason for it is that the invalid-feedback div is not a direct sibling of the the input control.

This has been an issue with the alpha/beta versions however I was under the impression that this has been fixed in the 4.0 release. (At least the relevant ticket has been closed.)

So, how can I use the bootstrap validation if I can not have the feedback text as a direct sibling of the relevant input control? (It is simply not feasible in my application.)

Here is a fiddle: https://jsfiddle.net/zygrsrox/


回答1:


You're right, the intention is that the input is a sibling of the feedback message. The only way you can force the invalid-feeback to show is to use something like d-block (or some custom CSS selector). Perhaps you can add d-block programatically in your app during validation.

<div class="form-row">
  <label class="form-control-label">Name:</label>
  <div class="col-4">
    <input class="form-control is-invalid" min="0" type="number"/>
  </div>
  <div class="col-4">
    <div class="invalid-feedback d-block">
    Invalid Feedback Text
    </div>
  </div>
</div>


来源:https://stackoverflow.com/questions/48401656/bootstrap-4-0-invalid-feedback-doesnt-show

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!