javascript - Change bootstrap validation message color to red - Stack Overflow

I have a form that posts an error message if an invalid email is entered. I'd like the error messa

I have a form that posts an error message if an invalid email is entered. I'd like the error message text to be changed to red. How can I do this?

$('#subscribe-form').bootstrapValidator({
  live: 'disabled',
  fields: {
    email: {
      validators: {
        emailAddress: {
          message: 'Please enter a valid email address'
        }
      }
    },
  }
});
<script src=".1.1/jquery.min.js"></script>
<form role="form" id="subscribe-form">
  <div class="form-group">
    <input type="email" class="form-control custom-email" name="email" id="email" placeholder="Email Address">
  </div>
  <button type="submit" class="btn btn-large custom-button">Sign up !</button>
</form>

I have a form that posts an error message if an invalid email is entered. I'd like the error message text to be changed to red. How can I do this?

$('#subscribe-form').bootstrapValidator({
  live: 'disabled',
  fields: {
    email: {
      validators: {
        emailAddress: {
          message: 'Please enter a valid email address'
        }
      }
    },
  }
});
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form role="form" id="subscribe-form">
  <div class="form-group">
    <input type="email" class="form-control custom-email" name="email" id="email" placeholder="Email Address">
  </div>
  <button type="submit" class="btn btn-large custom-button">Sign up !</button>
</form>

Share Improve this question edited Dec 28, 2017 at 17:37 Bhuwan 16.9k5 gold badges37 silver badges60 bronze badges asked Dec 28, 2017 at 17:32 user8110974user8110974 3
  • Try this formvalidation.io/examples/changing-success-error-colors – f78xd23 Commented Dec 28, 2017 at 17:41
  • As a heads up - Validator hasn't updated its support for BS4 yet and some of the naming conventions have changed. If you end up adopting BS4 in your project there are CSS workarounds in GitHub to address error-coloring. – Robert Commented Dec 28, 2017 at 20:04
  • @f78xd23 this link no longer exists. FYI – Pamela Cook - LightBe Corp Commented Jul 14, 2020 at 14:50
Add a ment  | 

2 Answers 2

Reset to default 4

Just add below css in your code

.has-error .help-block {
  color: red;
}

$('#subscribe-form').bootstrapValidator({
  live: 'disabled',
  fields: {
    email: {
      validators: {
        emailAddress: {
          message: 'Please enter a valid email address'
        }
      }
    },
  }
});
.has-error .help-block {
  color: red;
}
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare./ajax/libs/bootstrap-validator/0.5.3/js/bootstrapValidator.min.js"></script>
<form role="form" id="subscribe-form">
  <div class="form-group">
    <input type="email" class="form-control custom-email" name="email" id="email" placeholder="Email Address">
  </div>
  <button type="submit" class="btn btn-large custom-button">Sign up !</button>
</form>

If Bootstrap is added correctly you should already get error text as red. If not, this will fix that.

small.help-block {
   color: #F44336 !important;
}

$('#subscribe-form').bootstrapValidator({
  live: 'disabled',
  fields: {
    email: {
      validators: {
        emailAddress: {
          message: 'Please enter a valid email address'
        }
      }
    },
  }
});
small.help-block {
  color: #F44336 !important;
}
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn./bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://maxcdn.bootstrapcdn./bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare./ajax/libs/bootstrap-validator/0.5.3/js/bootstrapValidator.js"></script>

<form role="form" id="subscribe-form">

  <div class="form-group">
    <input type="email" class="form-control custom-email" name="email" id="email" placeholder="Email Address">
  </div>

  <button type="submit" class="btn btn-large custom-button"> Sign up ! </button>
</form>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744254489a4565328.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信