Simplify form validation states while enabling them to be applied to one field at a time.

This commit is contained in:
Mark Otto
2012-12-26 15:57:52 -06:00
parent d0baa99aed
commit dc5c6d6be8
5 changed files with 64 additions and 138 deletions

View File

@@ -342,15 +342,15 @@ input[type="checkbox"] {
// --------------------------
// Warning
.control-group.warning {
.has-warning {
.formFieldState(@state-warning-text, @state-warning-text, @state-warning-background);
}
// Error
.control-group.error {
.has-error {
.formFieldState(@state-error-text, @state-error-text, @state-error-background);
}
// Success
.control-group.success {
.has-success {
.formFieldState(@state-success-text, @state-success-text, @state-success-background);
}
@@ -523,15 +523,23 @@ select:focus:invalid {
// Increase spacing between groups
.control-group {
margin-bottom: @line-height-base / 2;
position: relative;
margin-bottom: @line-height-base;
.clearfix();
input,
select,
textarea,
.uneditable-input {
margin-bottom: 0;
}
}
// Float the labels left
.control-group > .control-label {
float: left;
width: @component-offset-horizontal - 20;
padding-top: 5px;
padding-top: 6px;
text-align: right;
}

View File

@@ -122,25 +122,14 @@
// FORMS
// --------------------------------------------------
// Mixin for form field states
.formFieldState(@text-color: #555, @border-color: #ccc, @background-color: #f5f5f5) {
// Set the text color
.control-label,
.help-block,
.help-inline {
// Color the label text
.control-label {
color: @text-color;
}
// Style inputs accordingly
.checkbox,
.radio,
input,
select,
textarea {
color: @text-color;
}
input,
select,
textarea {
// Set the border and box shadow on specific inputs to match
.input-with-feedback {
padding-right: 32px; // to account for the feedback icon
border-color: @border-color;
.box-shadow(inset 0 1px 1px rgba(0,0,0,.075)); // Redeclare so transitions work
&:focus {
@@ -149,13 +138,6 @@
.box-shadow(@shadow);
}
}
// Give a small background color for input-prepend/-append
.input-prepend .add-on,
.input-append .add-on {
color: @text-color;
background-color: @background-color;
border-color: @text-color;
}
}