Bootstrap: has-error does not change the color of buttons in an input-group

Created on 30 Nov 2013  Â·  14Comments  Â·  Source: twbs/bootstrap

Buttons in an input-group do not get their border colour changed when there is a parent element with has-error .

Example:

<div class="has-error" style="margin: 2em; width: 300px;">
<div class="input-group">
    <input type="text" class="form-control" value="zzz">
    <span class="input-group-btn">
        <button type="button" class="btn btn-default">Search</button>
    </span>
</div>
<p class="help-block">No results found for the provided criteria</p>
</div>

See the attached picture to see how it renders.
screen shot 2013-11-30 at 16 40 26

I would expect something more like the screen shot below.
screen shot 2013-11-30 at 16 38 42

css

Most helpful comment

Assuming .has-warning has this effect on .input-group-addon :

.has-warning .input-group-addon {
    color: #8a6d3b;
    background-color: #fcf8e3;
    border-color: #8a6d3b;
}

Why not adding that kind of rule ?

.has-warning .input-group-btn .btn.btn-default {
    color: #8a6d3b;
    background-color: #fcf8e3;
    border-color: #8a6d3b;
}

That way, the button is colored according to input validation state, but only if it has a default style (btn-default). That seems to be the expected behavior.
And if the button has a specific helper style (btn-danger, btn-warning ...), it is not overwritten.

All 14 comments

Just change .btn-default to .btn-danger.

I think we can't recolor the button text in the general case because it might be a colored button already, which would make it look bad.

yes .btn-danger goes well in that context.

Yeah, we won't be able to do this per @cvrebert's comment.

@adelinor :)

@ZDroid :+1: many thanks. Do you know if, in theory, the change of a class in an element generates events?

jQuery or pure JS? Are you talking about changing button state class if input has error?

Yes, I would need to change the button state class so that it is consistent with the input group class.

Your example shows exactly that, thank you very much :)

:)

2013/12/3 adelinor [email protected]

Yes, I would need to change the button state class so that it is
consistent with the input group class.

Your example shows exactly that, thank you very much :)

—
Reply to this email directly or view it on GitHubhttps://github.com/twbs/bootstrap/issues/11659#issuecomment-29751997
.

Zlatan Vasović - _ZDroid_

And here is an example based on the one above with AngularJS: http://jsfiddle.net/adelinor/Pty3g/

:)

2013/12/8 adelinor [email protected]

And here is an example based on the one above with AngularJS:
http://jsfiddle.net/adelinor/Pty3g/

—
Reply to this email directly or view it on GitHubhttps://github.com/twbs/bootstrap/issues/11659#issuecomment-30093365
.

Zlatan Vasović - _ZDroid_

Fixed in v3.1.1. We haven't outlined the button entirely, but we have fixed the border colors to behave more appropriately.

Assuming .has-warning has this effect on .input-group-addon :

.has-warning .input-group-addon {
    color: #8a6d3b;
    background-color: #fcf8e3;
    border-color: #8a6d3b;
}

Why not adding that kind of rule ?

.has-warning .input-group-btn .btn.btn-default {
    color: #8a6d3b;
    background-color: #fcf8e3;
    border-color: #8a6d3b;
}

That way, the button is colored according to input validation state, but only if it has a default style (btn-default). That seems to be the expected behavior.
And if the button has a specific helper style (btn-danger, btn-warning ...), it is not overwritten.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  Â·  3Comments

bellwood picture bellwood  Â·  3Comments

athimannil picture athimannil  Â·  3Comments

steve-32a picture steve-32a  Â·  3Comments

ziyi2 picture ziyi2  Â·  3Comments