Defining a `required` field in Bootstrap

后端 未结 7 616
[愿得一人]
[愿得一人] 2020-12-05 03:43

How do I define text field as required (with red border) in Twitter Bootstrap 3?

required=\"required\" doesn\'t work...



        
相关标签:
7条回答
  • 2020-12-05 04:15

    To make a field required, use required or required="true"

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

    0 讨论(0)
  • 2020-12-05 04:19

    Use 'needs-validation' apart from form-group, it will work.

    0 讨论(0)
  • 2020-12-05 04:21

    Try using required="true" in bootstrap 3

    0 讨论(0)
  • 2020-12-05 04:23

    If wont work in case you have something like : novalidate="novalidate" attached to your form.

    0 讨论(0)
  • 2020-12-05 04:26

    Update 2018

    Since the original answer HTML5 validation is now supported in all modern browsers. Now the easiest way to make a field required is simply using the required attibute.

    <input type="email" class="form-control" id="exampleInputEmail1" required>

    or in compliant HTML5:

    <input type="email" class="form-control" id="exampleInputEmail1" required="true">
    

    Read more on Bootstrap 4 validation


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

    For example has-error will show a red border around the input. However, this will have no impact on the actual validation of the field. You'd need to add some additional client (javascript) or server logic to make the field required.

    Demo: http://bootply.com/90564


    0 讨论(0)
  • 2020-12-05 04:30

    Check out native HTML5 form validation:

    http://www.the-art-of-web.com/html/html5-form-validation/

    0 讨论(0)
提交回复
热议问题