diff --git a/docs/4.0/components/forms.md b/docs/4.0/components/forms.md index 90a77225b0..3830f5a9f1 100644 --- a/docs/4.0/components/forms.md +++ b/docs/4.0/components/forms.md @@ -724,15 +724,21 @@ For custom Bootstrap form validation messages, you'll need to add the `novalidat When attempting to submit, you'll see the `:invalid` and `:valid` styles applied to your form controls. {% example html %} -
+
+
+ Looks good! +
+
+ Looks good! +
@@ -777,16 +783,19 @@ When attempting to submit, you'll see the `:invalid` and `:valid` styles applied // Example starter JavaScript for disabling form submissions if there are invalid fields (function() { 'use strict'; - window.addEventListener('load', function() { - var form = document.getElementById('needs-validation'); - form.addEventListener('submit', function(event) { - if (form.checkValidity() === false) { - event.preventDefault(); - event.stopPropagation(); - } - form.classList.add('was-validated'); - }, false); + // Fetch all the forms we want to apply custom Bootstrap validation styles to + var forms = document.getElementsByClassName('needs-validation'); + // Loop over them and prevent submission + var validation = Array.prototype.filter.call(forms, function(form) { + form.addEventListener('submit', function(event) { + if (form.checkValidity() === false) { + event.preventDefault(); + event.stopPropagation(); + } + form.classList.add('was-validated'); + }, false); + }); }, false); })(); @@ -847,10 +856,16 @@ We recommend using client side validation, but in case you require server side,
+
+ Looks good! +
+
+ Looks good! +
@@ -933,6 +948,67 @@ Our example forms show native textual ``s above, but form validation styl {% endexample %} +### Tooltips + +If your form layout allows it, you can swap the `.{valid|invalid}-feedback` classes for `.{valid|invalid}-tooltip` classes to display validation feedback in a styled tooltip. Be sure to have a parent with `position: relative` on it for tooltip positioning. In the example below, our column classes have this already, but your project may require an alternative setup. + +{% example html %} +
+
+
+ + +
+ Looks good! +
+
+
+ + +
+ Looks good! +
+
+
+ +
+
+ @ +
+ +
+ Please choose a unique and valid username. +
+
+
+
+
+
+ + +
+ Please provide a valid city. +
+
+
+ + +
+ Please provide a valid state. +
+
+
+ + +
+ Please provide a valid zip. +
+
+
+ +
+{% endexample %} + ## Custom forms For even more customization and cross browser consistency, use our completely custom form elements to replace the browser defaults. They're built on top of semantic and accessible markup, so they're solid replacements for any default form control. diff --git a/scss/mixins/_forms.scss b/scss/mixins/_forms.scss index d25df182df..627e0dc82c 100644 --- a/scss/mixins/_forms.scss +++ b/scss/mixins/_forms.scss @@ -27,7 +27,6 @@ @mixin form-validation-state($state, $color) { - .#{$state}-feedback { display: none; width: 100%; @@ -41,7 +40,7 @@ top: 100%; z-index: 5; display: none; - width: 250px; + max-width: 100%; // Contain to parent when possible padding: .5rem; margin-top: .1rem; font-size: .875rem;