Defining the `required` field in Bootstrap

How to define a text box as needed (with a red border) in Twitter Bootstrap 3?

required="required" does not work ...

 <form role="form"> <div class="form-group"> <label for="exampleInputEmail1">Email address</label> <input type="email" class="form-control" id="exampleInputEmail1" placeholder="Enter email"> </div> <div class="form-group"> <label for="exampleInputPassword1">Password</label> <input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password"> </div> <div class="form-group"> <label for="exampleInputFile">File input</label> <input type="file" id="exampleInputFile"> <p class="help-block">Example block-level help text here.</p> </div> <div class="checkbox"> <label> <input type="checkbox"> Check me out </label> </div> <button type="submit" class="btn btn-default">Submit</button> </form> 
+46
twitter-bootstrap-3
Oct 28 '13 at 16:53 on
source share
6 answers

Try using required="true" in bootstrap 3

+71
Dec 10 '14 at 16:26
source share
— -

In Bootstrap 3, you can apply the "validation state" class to the parent element: http://getbootstrap.com/css/#forms-control-validation

For example, has-error displays a red border around the input. However, this will not affect the actual field validation. You will need to add additional client (javascript) or server logic to make the desired field.

Demo: http://bootply.com/90564

+46
Oct 28 '13 at 17:02
source share
+6
Dec 18 '14 at 6:35
source share

Form validation can be enabled in markup via data-api or via JavaScript. Automatically enable form validation by adding data-toggle="validator" to your form element.

 <form role="form" data-toggle="validator"> ... </form> 

Or activate the check using JavaScript:

 $('#myForm').validator() 

and you need to use the required flag in the input field

Click here for more details.

+4
May 28 '15 at 11:34
source share

If you are not working, if you have something like: novalidate = "novalidate" attached to your form.

+1
Nov 29 '16 at 13:53 on
source share

To make the required field use required or required="true"

I think required="required" deprecated in version 3 of the bootstrap.

0
Jun 23 '15 at 7:01
source share



All Articles