Bootstrap: Validation states with form-inline fields? -
is there way use bootstrap's form field validation states/classes (warning, error, info, success) on form-inline fields (without using control-group)?
i'm using bootstrap, , have large form uses form-horizontal class layout. however, there areas within form fields need inline (for example, city/state/zip). i'm using form-inline this, works fine. here's basic markup:
<form id="account-form" class="form-horizontal" method="post" action="" novalidate> <!-- address --> <div class="control-group"> <label class="control-label">address</label> <div class="controls"> <input type="text" name="address" /> </div> </div> <!-- city, state, zip --> <div class="control-group"> <label class="control-label">city</label> <div class="controls form-inline"> <input type="text" name="city" /> <label>state</label> <input type="text" name="state" /> <label>zip code</label> <input type="text" name="zipcode" /> </div> </div> </form> in particular situation need handle validation manually. unfortunately, seems bootstrap's validation state classes must applied control-group; can see in example above, control-group in case contains multiple fields. tried wrapping individual fields within control-group spans or divs, control-group not play nicely @ when used both form-inline , form-horizontal together!
is there css class or other rule can attach field directly (or otherwise-innocent field wrapper) apply these styles individual fields, without having redeclare standard bootstrap styles??
you create custom less code , recompile bootstrap:
add @import "_custom.less"; less/bootstrap.less
create less/_custom.less:
// mixin inline form field states .inlineformfieldstate(@warning: success,@textcolor: #555, @bordercolor: #ccc, @backgroundcolor: #f5f5f5) { // set text color label.@{warning}, .help-block .@{warning}, .help-inline .@{warning}{ color: @textcolor; } // style inputs accordingly .checkbox .@{warning}, .radio .@{warning}, input.@{warning}, select.@{warning}, textarea.@{warning} { color: @textcolor; } input.@{warning}, select.@{warning}, textarea.@{warning} { border-color: @bordercolor; .box-shadow(inset 0 1px 1px rgba(0,0,0,.075)); // redeclare transitions work &:focus { border-color: darken(@bordercolor, 10%); @shadow: inset 0 1px 1px rgba(0,0,0,.075), 0 0 6px lighten(@bordercolor, 20%); .box-shadow(@shadow); } } // give small background color input-prepend/-append .input-prepend .add-on .@{warning}, .input-append .add-on .@{warning} { color: @textcolor; background-color: @backgroundcolor; border-color: @textcolor; } } .form-inline{ .inlineformfieldstate(success, @successtext, @successtext, @successbackground); .inlineformfieldstate(warning, @warningtext, @warningtext, @warningbackground); .inlineformfieldstate(info, @infotext, @infotext, @infobackground); .inlineformfieldstate(error, @errortext, @errortext, @errorbackground); } this mixin based on .formfieldstate in less/mixins.less. after recompile bootstrap use (see also: http://jsfiddle.net/bassjobsen/k3re3/):
<form> <div class="container"> <div class="control-group"> <div class="controls form-inline"> <label class="error">city</label> <input class="error" type="text" name="city" /> <label class="warning">state</label> <input class="warning" type="text" name="state" /> <label class="success">zip code</label> <input class="success" type="text" name="zipcode" /> <label class="info">street</label> <input class="info" type="text" name="street" /> </div> </div> </div> </form>
Comments
Post a Comment