Boostrap Validator

0

Well, I'm trying to do a validator with Boostrap but it's not working. I want the input weight to be for example: 70 kg. The regex I think is working but when I submit, div.invalid-feedback does not appear

<input class="form-control" type="text"  name ="peso" pattern="(\d*\.?\d+)\s*(lbs?|kg)" required placeholder="Peso" data-error="Isso nao é kg">
                                <div class="invalid-feedback">Isso não é kg</div>

Thank you

    
asked by anonymous 02.11.2017 / 22:45

1 answer

1

@JorgeFerreira failed to insert class help-block with-errors that uses error generated by data-error="Isso nao é kg"

$(document).ready(function(){
  $("form").submit(function(){  
  var input_peso = $('#peso').val();
  console.log(input_peso);
  return false;
    });
});
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" rel="stylesheet" />
<form name="form" data-toggle="validator" role="form" action="#">
<div class="form-group">
    <label for="peso" class="control-label">Peso:</label>
  <input id="peso" class="form-control" type="text" name="peso" pattern="^\d+(?:\.\d+)?\s*(?:kg|lbs|t)$" required placeholder="Peso" data-error="Isso nao é kg">
 <div class="help-block with-errors"></div>
  </div>

  <div class="form-group">
    <button type="submit" class="btn btn-primary">Submit</button>
  </div>
</form>

<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/1000hz-bootstrap-validator/0.11.9/validator.min.js"></script>
    
03.11.2017 / 14:21