This course will be retired on July 14, 2025.
Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
- Introducing Form Validation 4:04
- Form Validation 5 questions
- Implementing Server-Side Validation Using ModelState 5:45
- Adding Server-Side Validations Using ModelState 1 objective
- Implementing Server-Side Validation Using Data Annotations 4:36
- Adding Server-Side Validations Using Data Annotations 1 objective
- Displaying Validation Messages 5:31
- Displaying Validation Messages 1 objective
- Implementing Unobtrusive Client-Side Validation 10:11
- Improving Validation CSS Styles 6:03
- Section Review 5 questions

- 2x 2x
- 1.75x 1.75x
- 1.5x 1.5x
- 1.25x 1.25x
- 1.1x 1.1x
- 1x 1x
- 0.75x 0.75x
- 0.5x 0.5x
Let’s see how to update our web app to take full advantage of Bootstrap’s available form styles.
Follow Along
To follow along commiting your changes to this course, you'll need to fork the aspnet-fitness-frog repo. Then you can clone, commit, and push your changes to your fork like this:
git clone <your-fork>
cd aspnet-fitness-frog
git checkout tags/v4.6 -b improving-validation-css-styles
Code
Here’s the JavaScript code snippet that you need to add to the layout page in order to fully support the available Bootstrap form validation styles.
(function ($) {
var defaultOptions = {
validClass: 'has-success',
errorClass: 'has-error',
highlight: function (element, errorClass, validClass) {
$(element).closest('.form-group')
.removeClass(validClass)
.addClass(errorClass);
},
unhighlight: function (element, errorClass, validClass) {
$(element).closest('.form-group')
.removeClass(errorClass)
.addClass(validClass);
}
};
$.validator.setDefaults(defaultOptions);
$.validator.unobtrusive.options = {
errorClass: defaultOptions.errorClass,
validClass: defaultOptions.validClass,
};
})(jQuery);
Additional Learning
See Bootstrap’s official documentation for more information about its available form control validation styles.
If you’d like to learn more about JavaScript or jQuery, see these Treehouse courses.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up-
Ar33ss Leon
4,621 Points1 Answer
-
Rolando Bernal
18,105 Points3 Answers
View all discussions for this video
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up