skip to Main Content

I create a form where I check the length of a password. If length is <6 then an error message appears.
This message is created by javascript. And here is the problem, the message appears with a line break after every word. I also tried it with ‘ ‘ but that doesn’t work:(

How do I create the message without the line breaks?

Thanks for your help!

$("#registerPass").on("focusout", function() {

  if ($("#registerPass").val().length < 6) {
    $(this).removeClass("valid").addClass("invalid");
    $('#registerPass + label').attr('data-error', 'Mindestens 6 Zeichen nötig!');
  }

});
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/mdbootstrap/4.8.11/css/mdb.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mdbootstrap/4.8.11/js/mdb.min.js"></script>



<form style="color: #757575;" action="#!">
  <div class="md-form mb-5">
    <input type="password" id="registerPass" class="form-control" required>
    <label data-error="" data-success="OK" for="registerPass">Passwort</label>
  </div>
</form>

3

Answers


  1. Try to add width: 100% to the label element. I checked it and updated codebase below.

    $("#registerPass").on("focusout", function() {
      if ($("#registerPass").val().length < 6) {
        $(this).removeClass("valid").addClass("invalid");
        $('#registerPass + label').attr('data-error', 'Mindestens 6 Zeichen nötig!');
      }
    });
    <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
    <link href="https://cdnjs.cloudflare.com/ajax/libs/mdbootstrap/4.8.11/css/mdb.min.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/mdbootstrap/4.8.11/js/mdb.min.js"></script>
    
    <form style="color: #757575;" action="#!">
      <div class="md-form mb-5">
        <input type="password" id="registerPass" class="form-control" required>
        <label data-error="" data-success="OK" for="registerPass" style="width: 100%">Passwort</label>
      </div>
    </form>
    Login or Signup to reply.
  2. Try adding white-space: nowrap to your css and target the ::after pseudo-element of the label.

    https://jsfiddle.net/jvko4wdq/

    Alternatively, you may also set the label width as 100% with CSS.

    Login or Signup to reply.
  3. Set 100% width to element, thats it!

    <label data-error="" data-success="OK" for="registerPass" style='width: 100%'>Passwort</label>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search