Skip to content

Commit 4972f87

Browse files
committed
Update form validation docs
- Give some guidance on when someone might use any of the three validation states. Fixes #18702. - Improve the examples to provide examples of supporting validation text with the new `.form-control-feedback`, as well as always-present help text. Nullifies #18704.
1 parent 5744c58 commit 4972f87

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

docs/components/forms.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -660,15 +660,22 @@ Block help text—for below inputs or for longer lines of help text—can be eas
660660

661661
## Validation
662662

663-
Bootstrap includes validation styles for danger, warning, and success states on form controls.
663+
Bootstrap includes validation styles for danger, warning, and success states on form controls. Here's a rundown of how they work:
664664

665-
- To use, add `.has-warning`, `.has-danger`, or `.has-success` to the parent element. Any `.form-control-label`, `.form-control`, and `.text-help` within that element will receive the validation styles.
666665
- To use, add `.has-warning`, `.has-danger`, or `.has-success` to the parent element. Any `.form-control-label`, `.form-control`, or custom form element will receive the validation styles.
667666
- Contextual validation text, in addition to your usual form field help text, can be added with the use of `.form-control-feedback`. This text will adapt to the parent `.has-*` class. By default it only includes a bit of `margin` for spacing and a modified `color` for each state.
668667
- Validation icons are `url()`s configured via Sass variables that are applied to `background-image` declarations for each state.
669668
- You may use your own base64 PNGs or SVGs by updating the Sass variables and recompiling.
670669
- Icons can also be disabled entirely by setting the variables to `none` or commenting out the source Sass.
671670

671+
Generally speaking, you'll want to use a particular state for specific types of feedback:
672+
673+
- **Danger** is great for when there's a blocking or required field. A user *must* fill in this field properly to submit the form.
674+
- **Warning** works well for input values that are in progress, like password strength, or soft validation before a user attempts to submit a form.
675+
- And lastly, **success** is ideal for situations when you have per-field validation throughout a form and want to encourage a user through the rest of the fields.
676+
677+
Here are some examples of the aforementioned classes in action.
678+
672679
{% comment %}
673680
{% callout warning %}
674681
#### Conveying validation state to assistive technologies and colorblind users
@@ -683,16 +690,24 @@ Ensure that an alternative indication of state is also provided. For instance, y
683690
<div class="form-group has-success">
684691
<label class="form-control-label" for="inputSuccess1">Input with success</label>
685692
<input type="text" class="form-control form-control-success" id="inputSuccess1">
693+
<div class="form-control-feedback">Success! You've done it.</div>
694+
<small class="text-muted">Example help text that remains unchanged.</small>
686695
</div>
687696
<div class="form-group has-warning">
688697
<label class="form-control-label" for="inputWarning1">Input with warning</label>
689698
<input type="text" class="form-control form-control-warning" id="inputWarning1">
699+
<div class="form-control-feedback">Shucks, check the formatting of that and try again.</div>
700+
<small class="text-muted">Example help text that remains unchanged.</small>
690701
</div>
691702
<div class="form-group has-danger">
692703
<label class="form-control-label" for="inputDanger1">Input with danger</label>
693704
<input type="text" class="form-control form-control-danger" id="inputDanger1">
705+
<div class="form-control-feedback">Shit, that username's taken. Try another?</div>
706+
<small class="text-muted">Example help text that remains unchanged.</small>
694707
</div>
708+
{% endexample %}
695709

710+
{% example html %}
696711
<div class="checkbox has-success">
697712
<label>
698713
<input type="checkbox" id="checkboxSuccess" value="option1">

0 commit comments

Comments
 (0)