Book Image

Bootstrap for Rails

By : Syed F Rahman
Book Image

Bootstrap for Rails

By: Syed F Rahman

Overview of this book

Table of Contents (18 chapters)
Bootstrap for Rails
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Validation classes in Bootstrap forms


Bootstrap works well with HTML5's default form validation. Adding an attribute called required to any form element will prevent the form from being submitted. Bootstrap's JavaScript doesn't have any predefined validation functionality. It provides you with CSS classes that can be applied to the form elements on runtime. These classes are important to highlight which form element needs attention by the user.

Let's have a look at some of the form validation classes by Bootstrap:

  • .has-error: This class is used to highlight a red color

  • .has-warning: This class is used to highlight a dull yellow color

  • .has-success: This class is used to highlight a green color

These classes are applied to the .form-group element. For example, adding the .has-error class to any .form-group element will highlight both label and form elements with a red color:

<div class="form-group has-error">
  <label for="emailField">Email address</label>
  <input type=...