I have been looking into Bootstrap 4 - beta, however when using .is-invalid
with .input-group
it doesn't seem to show up.
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet" /> <div class="form-group"> <label for="label">Label</label> <div class="input-group"> <div class="input-group-addon"> label </div> <input type="text" value="" name="label" class="form-control is-invalid"> </div> <div class="invalid-feedback is-invalid"> <strong>Invalid Label</strong> </div> </div>
How are you meant to display an invalid message while using .input-group
?
Adding the following CSS works as a workaround, but it seems odd.
.form-group.is-invalid { .invalid-feedback { display: block; } }
1. Required attribute: If you want to make an input mandatory to be entered by the user, you can use the required attribute. This attribute can be used with any input type such as email, URL, text, file, password, checkbox, radio, etc. This can help to make any input field mandatory.
Here's how form validation works with Bootstrap: HTML form validation is applied via CSS's two pseudo-classes, :invalid and :valid . It applies to <input> , <select> , and <textarea> elements. Bootstrap scopes the :invalid and :valid styles to parent .was-validated class, usually applied to the <form> .
This is pretty useful in giving a visual indication to the user when a form field is required. There will now be a nice little “*” after the label for “Required Field”.
Bootstrap 4 Input Groups input-group class is a container to enhance an input by adding an icon, text or a button in front or behind the input field as a "help text". Use . input-group-prepend to add the help text in front of the input, and . input-group-append to add it behind the input.
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>
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. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With