Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
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 upRelated 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