-
-
Notifications
You must be signed in to change notification settings - Fork 78.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.invalid-feedback doesn't show for .input-group with an invalid control #23454
Comments
In your example, you might need to place the <div class="form-group col-md-4">
<label class="form-control-label is-invalid" for="valuation_value">Estimated Value</label>
<div class="input-group is-invalid">
<span class="input-group-addon">£</span>
<input class="form-control is-invalid" min="0" type="number" value="" name="valuation[value]">
<!-- feeback right after input -->
<div class="invalid-feedback">can't be blank, is not a number</div>
</div>
</div> |
@aedart If I do that, it tries to fit in the feedback inside the input-group, which breaks the layout |
Yes, you are right. Perhaps a Also, I just realized that you are also setting the |
I tried on the parent div. In the end, I've added the following which does what I want, but my gut says this should work off the shelf: .input-group.is-invalid {
~ .invalid-feedback {
display: block;
}
} |
You are right, just created the fiddle that shows you point: https://jsfiddle.net/aedart/tLwsztc0/ However, I'm not sure if the authors are going for this or not. But it does seem like a clear "lack" that invalid-feedback's appearance is entirely controlled by a siblings' state, ... |
Definitely something to see if we can support. We're also missing proper support for checks and radios as mentioned in another issue. |
Sorry, to elaborate, the problem is we're not actively asking folks to add a class to the parent of an input. With the HTML5 validation move in Beta 1, we're triggering everything off the state of the input. We need to see if there's something else we can do for the input group, but it's tough given that markup and styling for presenting inputs that way. |
Related to this issue, when using <div class="input-group is-invalid">
<div class="input-group-addon">%</div>
<input type="number" class="form-control" required>
</div>
<div class="invalid-feedback">
</div> This snippet generates something that looks like this: Applying border to the entire |
To be clear, that's not a default input control—that's a hacked up custom form control :). |
I'm having the same problem.
I know this is not ideal, but at least it allowed me to move forward. |
I was encountering this issue as well, trying to figure out how to get the invalid-feedback to show when the invalid-feedback is not a sibling of the input (i.e input groups, etc.) and using a feedback text for custom file-input is another good example where this new method fails. I don't think HTML5 validation is actually ready for the real web yet (not until CSS parent selectors become available, which I think is never). Once could add in a JavaScript routine to monitor the validity state of an input (or the is-valid/invalid class) and then check for any elements that may have a But it feels bad using JavaScript to correct this shortcoming. Having a 'valid-feedback` element would be nice as well, or at least the ability to change the color of the invalid-feedback to green It would be at least nice to get the ability to place a class on the input-group, and for radio-groups or stacked check boxes, etc (i.e feedback messages to select one) |
I'm having this issue as well.
Being that I use solely 'server validation' as they're calling it, I need that parent element 'is-invalid' hook back? |
How would this be done on a centered bootstrap form centered using the grid system and I wanted to show validation message under the input box on an grouped input box ? |
Here's my temporary workaround until they fix this: https://codepen.io/evshell18/pen/WEzOdj It's not perfect, and only really works well as long as you have only 1 line of validation text. If your text is longer than a line it might be in danger of flowing over the elements below it, as shown in the example. Hopefully this gets fixed soon. It should be based on applying the |
temporary solution is to add these css .input-group {
flex-wrap: wrap!important;
}
.input-group .invalid-feedback {
flex-basis: 100%!important;
} this will force the feedback to wrap into the 2nd line, then in your html put feedback below input <div class="input-group is-invalid">
<div class="input-group-addon"></div>
<input type="number" class="form-control" required>
<div class="invalid-feedback"></div>
</div>` |
@jwnoz it does not work correctly when the addon is at the end of group: the right border is removed. It is caused by the |
@tbolon for that you need to manually add back the border .input-group .input-group-addon:nth-last-child(2) {
border-left: 0!important;
border-right: 1px solid rgba(0,0,0,.15);
border-radius: .25rem!important;
border-top-left-radius: 0!important;
border-bottom-left-radius: 0!important;
} use nth-child selector if you have more than one feedback |
If you ask me, all solutions above seem hacky - at best. The validation support for forms in Alpha 6 and TWBS 3 was a lot better. We're now sorta forced to rely on HTML5 input states rather and advanced markup for column model, input grouped input's. Eagerly looking forward to a solution, for now I rely on my own CSS skills to make it work, as even examples from the docs don't support is-invalid properly. :( |
I have the same situation as @tochoromero and just overwrite it. |
I'm using angular, and I control the visibility of the feedback with that so I don't care about the nearby element with the This is my solution to add the <div class="invalid-feedback d-block" ng-if="form.$submitted && form.username.$invalid"> |
i ran into this issue as well as i personally use VueJS to i handle all my own showing of validation errors and classes etc. I have built the following quick CSS file that extends the bootstrap 4-beta validation and allows you to do what you did originally in bootstrap 3, I have also added a JSFiddle example link, hope this helps anyone looking to do something similar. https://github.com/lilpug/bootstrap-4-beta-validation |
Urgh, just ran in to this myself. Why can’t we just have the |
We should be able to have both the old way and the new way. As well, it is nice to be able to show feedback in the success state as well, not just the invalid state. Edit: it appears that there is an undocumented |
damn: logged a question on stackoverflow before finding this issue. maybe the visibility there will create some up-votes for supporting both the |
Testing out something in https://codepen.io/emdeoh/pen/ZXXQKM. Not perfect yet, but wanted to capture something to see if I can make a fix in Beta 2. |
@mdo Interesting. It would be nice to be able to style the input addons too with the proper color/outline. One thought would be to use flex ordering, and place the input first, and all the addons after, which would allow them to be styled with sibling selectors. But this makes accessibility a bit awkward, as what is provided to screen readers is not in the same order as presentation (i.e. say a Still, It also doesn't work well with form-groups, where you might have the feedback outside of the input-group (say if someone is making a re-usable form-group component). Another consideration is when using a framework such as Angular, vue, React, etc, where validation is performed in the component (where more complex validation can take place, such as verifying that user's email exists in the DB, etc). There is no easy way to provide consistent feedback look and feel. One may as well throw away the form-group markup, as it doesn't work with many of the custom inputs. (custom file - and even plain file inputs - especially has issues with the pseudo I still think it would be worth while extending the You can still leave in native browser validation for those that want it. |
|
February 2019 and still no fix for this... input groups are broken for server-side validation. Bump |
It did the trick. I am using it in an Angular component , that's why I don't specify it further... |
is-invalid seems to be the way to go, you can conditionally use it with 'classnames'... import classNames from 'classnames'
Hope this helps! |
C’mon. Is this getting fixed properly? It’s been an issue since the beta(s), through two minor releases, and there’s now talk of version 5 when this is still an issue. @mdo? Can we get a definitive response as to the status of this bug and the Bootstrap’s team to fix it? It’s a tiny bit ridiculous people can’t have error messages show up for inputs unless they’re marked in a particular way (which may not be suitable for all apps). |
The error was that the invalid-feedback of forms wasn't displayed. The problem was solved with that link : twbs/bootstrap#23454 (comment)
There are two working solutions (aka hacks) to get the
<div class="section measurements-area" style="display: none">
<h4>Measure your test sample and upload the csv file</h4>
<form id="measurements-form" class="needs-validation" novalidate>
<div class="input-group input-group-sm">
<div class="custom-file flex-wrap">
<input type="file" class="custom-file-input" id="measurements" required>
<div class="invalid-feedback w-100">
The measurements file is required.
</div>
<label class="custom-file-label" for="measurements" data-browse="Browse">Upload measurements</label>
</div>
<div class="input-group-append">
<button class="btn btn-outline-primary" type="submit" id="recalibrate">Recalibrate</button>
</div>
</div>
</form>
</div>
<form id="measurements-form" class="needs-validation" novalidate>
<div class="input-group input-group-sm">
<div class="custom-file">
<input type="file" class="custom-file-input" id="measurements" required>
<div class="invalid-feedback" style="position: absolute; top: 3.0em">
The measurements file is required.
</div>
<label class="custom-file-label" for="measurements" data-browse="Browse">Upload measurements</label>
</div>
<div class="input-group-append">
<button class="btn btn-outline-primary" type="submit" id="recalibrate">Recalibrate</button>
</div>
</div>
</form> The downside to both of these is that Furthermore, The following solutions DO NOT work for
.input-group {
flex-wrap: wrap!important;
}
.input-group .invalid-feedback {
flex-basis: 100%!important;
} Also, the |
So why's this issue closed? Apparently, you need a hack (as summarized by @br3nt) to get it working, and the natural usage – just add the |
Yeah, whis the hell is this closed? Please reopen this. |
F**k it! I've just created a new ticket. #29439. |
Just thought I'd drop my workaround in Vue. You can probably translate it to other libraries pretty easily.
|
FWIW, this issue is quite old and there have been changes to the form validation styles to make things more bulletproof. v4.4 in particular I believe saw some improvements (see #29264). The input groups show invalid feedback: https://codepen.io/emdeoh/pen/PoqBdzN. That said, our docs show this working for custom styles and server side, but do note that input groups lose their rounded corners. (We have no way of targeting those corners reliably unfortunately.) |
It is still not completely consistent. Look at the right border of the input elements inside a .input-group. It is not rounded. |
@repoles He literally said this in his comment:
|
@stevebauman sorry, I hadn't seen that note. Thanks! |
I’ve spent the last hour trying to find a somewhat supported solution to this but there doesn’t seem to be one. Looks like a manual override like this comment above suggests is as good as it gets? |
@themustafaomar Yes, you can emulate |
The rounded corners issue can be solved with the border classes too: https://getbootstrap.com/docs/4.0/utilities/borders/ |
This is a known unresolved issue in Bootstrap 4 See: twbs/bootstrap#23454
Example:
Results in:
I would expect to see
can't be blank, is not a number
under the input-group.The text was updated successfully, but these errors were encountered: