aboutsummaryrefslogtreecommitdiff
path: root/docs/components/forms.md
diff options
context:
space:
mode:
authorMark Otto <[email protected]>2016-04-08 20:55:19 -0500
committerMark Otto <[email protected]>2016-04-08 20:55:19 -0500
commit80144d74d7435746f786e8eceae3a4adc07f93ac (patch)
treea6f1c8654961d2bd9c3ea2fa8639942826b9e489 /docs/components/forms.md
parent325c1d4c3cde965229c6f512739946f8076fc225 (diff)
parent2cc75671e143587ace7efaf79c5b3350a711d57d (diff)
downloadbootstrap-80144d74d7435746f786e8eceae3a4adc07f93ac.tar.xz
bootstrap-80144d74d7435746f786e8eceae3a4adc07f93ac.zip
Merge branch 'v4-dev' into v4-forms-cleanup
Diffstat (limited to 'docs/components/forms.md')
-rw-r--r--docs/components/forms.md174
1 files changed, 113 insertions, 61 deletions
diff --git a/docs/components/forms.md b/docs/components/forms.md
index 907bad705..14921b210 100644
--- a/docs/components/forms.md
+++ b/docs/components/forms.md
@@ -19,16 +19,16 @@ Remember, since Bootstrap utilizes the HTML5 doctype, **all inputs must have a `
{% example html %}
<form>
- <fieldset class="form-group">
+ <div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email">
<small id="emailHelp" class="text-muted">We'll never share your email with anyone else.</small>
- </fieldset>
- <fieldset class="form-group">
+ </div>
+ <div class="form-group">
<label for="exampleInputPassword1">Password</label>
<input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password">
- </fieldset>
- <fieldset class="form-group">
+ </div>
+ <div class="form-group">
<label for="exampleSelect1">Example select</label>
<select class="form-control" id="exampleSelect1">
<option>1</option>
@@ -37,8 +37,8 @@ Remember, since Bootstrap utilizes the HTML5 doctype, **all inputs must have a `
<option>4</option>
<option>5</option>
</select>
- </fieldset>
- <fieldset class="form-group">
+ </div>
+ <div class="form-group">
<label for="exampleSelect2">Example multiple select</label>
<select multiple class="form-control" id="exampleSelect2">
<option>1</option>
@@ -47,34 +47,37 @@ Remember, since Bootstrap utilizes the HTML5 doctype, **all inputs must have a `
<option>4</option>
<option>5</option>
</select>
- </fieldset>
- <fieldset class="form-group">
+ </div>
+ <div class="form-group">
<label for="exampleTextarea">Example textarea</label>
<textarea class="form-control" id="exampleTextarea" rows="3"></textarea>
- </fieldset>
- <fieldset class="form-group">
+ </div>
+ <div class="form-group">
<label for="exampleInputFile">File input</label>
<input type="file" class="form-control-file" id="exampleInputFile" aria-describedby="fileHelp">
<small id="fileHelp" class="text-muted">This is some placeholder block-level help text for the above input. It's a bit lighter and easily wraps to a new line.</small>
- </fieldset>
- <div class="radio">
- <label>
- <input type="radio" name="optionsRadios" id="optionsRadios1" value="option1" checked>
- Option one is this and that&mdash;be sure to include why it's great
- </label>
- </div>
- <div class="radio">
- <label>
- <input type="radio" name="optionsRadios" id="optionsRadios2" value="option2">
- Option two can be something else and selecting it will deselect option one
- </label>
- </div>
- <div class="radio disabled">
- <label>
- <input type="radio" name="optionsRadios" id="optionsRadios3" value="option3" disabled>
- Option three is disabled
- </label>
</div>
+ <fieldset class="form-group">
+ <legend>Radio buttons</legend>
+ <div class="radio">
+ <label>
+ <input type="radio" name="optionsRadios" id="optionsRadios1" value="option1" checked>
+ Option one is this and that&mdash;be sure to include why it's great
+ </label>
+ </div>
+ <div class="radio">
+ <label>
+ <input type="radio" name="optionsRadios" id="optionsRadios2" value="option2">
+ Option two can be something else and selecting it will deselect option one
+ </label>
+ </div>
+ <div class="radio disabled">
+ <label>
+ <input type="radio" name="optionsRadios" id="optionsRadios3" value="option3" disabled>
+ Option three is disabled
+ </label>
+ </div>
+ </fieldset>
<div class="checkbox">
<label>
<input type="checkbox"> Check me out
@@ -258,14 +261,14 @@ The `.form-group` class is the easiest way to add some structure to forms. Its o
{% example html %}
<form>
- <fieldset class="form-group">
+ <div class="form-group">
<label for="formGroupExampleInput">Example label</label>
<input type="text" class="form-control" id="formGroupExampleInput" placeholder="Example input">
- </fieldset>
- <fieldset class="form-group">
+ </div>
+ <div class="form-group">
<label for="formGroupExampleInput2">Another label</label>
<input type="text" class="form-control" id="formGroupExampleInput2" placeholder="Another input">
- </fieldset>
+ </div>
</form>
{% endexample %}
@@ -330,11 +333,16 @@ Because of this, you may need to manually address the width and alignment of ind
</form>
{% endexample %}
+{% callout warning %}
+ #### Alternatives to hidden labels
+ Assistive technologies such as screen readers will have trouble with your forms if you don't include a label for every input. For these inline forms, you can hide the labels using the `.sr-only` class. There are further alternative methods of providing a label for assistive technologies, such as the `aria-label`, `aria-labelledby` or `title` attribute. If none of these are present, assistive technologies may resort to using the `placeholder` attribute, if present, but note that use of `placeholder` as a replacement for other labelling methods is not advised.
+ {% endcallout %}
+
### Using the Grid
For more structured form layouts that are also responsive, you can utilize Bootstrap's [predefined grid classes](/layout/grid/#predefined-classes) or [mixins](/layout/grid/#sass-mixins) to create horizontal forms. Add the `.row` class to form groups and use the `.col-*-*` classes to specify the width of your labels and controls.
-Be sure to add `.form-control-label` to your `<label>`s as well so they're vertically centered with their associated labels.
+Be sure to add `.form-control-label` to your `<label>`s as well so they're vertically centered with their associated form controls. For `<legend>` elements, you can use `.form-control-legend` to make them appear similar to regular `<label>` elements.
{% example html %}
<div class="container">
@@ -351,29 +359,27 @@ Be sure to add `.form-control-label` to your `<label>`s as well so they're verti
<input type="password" class="form-control" id="inputPassword3" placeholder="Password">
</div>
</div>
- <div class="form-group row">
- <label class="col-sm-2">Radios</label>
- <div class="col-sm-10">
- <div class="radio">
- <label>
- <input type="radio" name="gridRadios" id="gridRadios1" value="option1" checked>
- Option one is this and that&mdash;be sure to include why it's great
- </label>
- </div>
- <div class="radio">
- <label>
- <input type="radio" name="gridRadios" id="gridRadios2" value="option2">
- Option two can be something else and selecting it will deselect option one
- </label>
- </div>
- <div class="radio disabled">
- <label>
- <input type="radio" name="gridRadios" id="gridRadios3" value="option3" disabled>
- Option three is disabled
- </label>
- </div>
+ <fieldset class="form-group">
+ <legend>Radio buttons</legend>
+ <div class="radio">
+ <label>
+ <input type="radio" name="optionsRadios" id="optionsRadios1" value="option1" checked>
+ Option one is this and that&mdash;be sure to include why it's great
+ </label>
</div>
- </div>
+ <div class="radio">
+ <label>
+ <input type="radio" name="optionsRadios" id="optionsRadios2" value="option2">
+ Option two can be something else and selecting it will deselect option one
+ </label>
+ </div>
+ <div class="radio disabled">
+ <label>
+ <input type="radio" name="optionsRadios" id="optionsRadios3" value="option3" disabled>
+ Option three is disabled
+ </label>
+ </div>
+ </fieldset>
<div class="form-group row">
<label class="col-sm-2">Checkbox</label>
<div class="col-sm-10">
@@ -385,8 +391,8 @@ Be sure to add `.form-control-label` to your `<label>`s as well so they're verti
</div>
</div>
<div class="form-group row">
- <div class="col-sm-offset-2 col-sm-10">
- <button type="submit" class="btn btn-secondary">Sign in</button>
+ <div class="offset-sm-2 col-sm-10">
+ <button type="submit" class="btn btn-primary">Sign in</button>
</div>
</div>
</form>
@@ -487,17 +493,17 @@ Use the `.checkbox-inline` or `.radio-inline` classes on a series of checkboxes
### Without labels
-Should you have no text within the `<label>`, the input is positioned as you'd expect. **Currently only works on non-inline checkboxes and radios.**
+Should you have no text within the `<label>`, the input is positioned as you'd expect. **Currently only works on non-inline checkboxes and radios.** Remember to still provide some form of label for assistive technologies (for instance, using `aria-label`).
{% example html %}
<div class="checkbox">
<label>
- <input type="checkbox" id="blankCheckbox" value="option1">
+ <input type="checkbox" id="blankCheckbox" value="option1" aria-label="...">
</label>
</div>
<div class="radio">
<label>
- <input type="radio" name="blankRadio" id="blankRadio1" value="option1">
+ <input type="radio" name="blankRadio" id="blankRadio1" value="option1" aria-label="...">
</label>
</div>
{% endexample %}
@@ -805,6 +811,33 @@ Custom checkboxes and radios can also be disabled. Add the `disabled` boolean at
</label>
{% endexample %}
+#### Validation states
+
+Add other states to your custom forms with our validation classes.
+
+{% example html %}
+<div class="form-group has-success">
+ <label class="custom-control custom-checkbox">
+ <input type="checkbox" class="custom-control-input">
+ <span class="custom-control-indicator"></span>
+ <span class="custom-control-description">Check this custom checkbox</span>
+ </label>
+</div>
+<div class="form-group has-warning">
+ <label class="custom-control custom-checkbox">
+ <input type="checkbox" class="custom-control-input">
+ <span class="custom-control-indicator"></span>
+ <span class="custom-control-description">Check this custom checkbox</span>
+ </label>
+</div>
+<div class="form-group has-danger m-b-0">
+ <label class="custom-control custom-checkbox">
+ <input type="checkbox" class="custom-control-input">
+ <span class="custom-control-indicator"></span>
+ <span class="custom-control-description">Check this custom checkbox</span>
+ </label>
+</div>
+{% endexample %}
#### Stacked
@@ -860,3 +893,22 @@ Here's how it works:
- We declare a `height` on the `<input>` for proper spacing for surrounding content.
In other words, it's an entirely custom element, all generated via CSS.
+
+#### Translating or customizing the strings
+
+The [`:lang()` pseudo-class](https://developer.mozilla.org/en-US/docs/Web/CSS/:lang) is used to allow for easy translation of the "Browse" and "Choose file..." text into other languages. Simply override or add entries to the `$custom-file-text` SCSS variable with the relevant [language tag](https://en.wikipedia.org/wiki/IETF_language_tag) and localized strings. The English strings can be customized the same way. For example, here's how one might add a Spanish translation (Spanish's language code is `es`):
+
+{% highlight scss %}
+$custom-file-text: (
+ placeholder: (
+ en: "Choose file...",
+ es: "Seleccionar archivo..."
+ ),
+ button-label: (
+ en: "Browse",
+ es: "Navegar"
+ )
+);
+{% endhighlight %}
+
+You'll need to set the language of your document (or subtree thereof) correctly in order for the correct text to be shown. This can be done using [the `lang` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/lang) or the [`Content-Language` HTTP header](https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.12), among other methods.