Problem Error: VanillaMasker: There is no element to bind

0

I'm using% VanillaMasker for validating a phone and date field, except that these elements are within a% w / w% w / w% I tried to play the function into a function of type:

jQuery('#form-basic-informations').on('click',function(){

But still not working ... returns the error in the console:

  

Error: lib : There is no element to bind.

jQuery('#form-basic-informations').on('click',function(){
    var telMask = ["(99) 9999-99999", "(99) 99999-9999"];
    var tel = document.querySelector("input[attrname=telefone]");
    VMasker(tel).maskPattern(telMask[0]);
    tel.addEventListener("input", inputHandler.bind(undefined, telMask, 14), false);

    var datMask = ["99/99/9999"];
    var dat = document.querySelector("input[attrname=dataNas]");
    VMasker(dat).maskPattern(datMask[0]);
    dat.addEventListener("input", inputHandler.bind(undefined, datMask, 14), false);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><linkhref="http://v4-alpha.getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet" />

<span><a href="" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#modalInfPessoais">Alterar informações pessoais</a></span>

<!-- Modal Inf Pessoais -->
<div class="modal" id="modalInfPessoais" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
        <h4 class="modal-title" id="myModalLabel">Teste</h4>
      </div>
      <form class="form-horizontal" id="form-basic-informations" action="#">
        <div class="modal-body">
          <fieldset>
            <div class="form-group">
              <div class="col-md-12">
                <input id="nome" name="nome" required type="text" placeholder="Nome" class="form-control input-md">
              </div>
            </div>
            <div class="form-group">
              <div class="col-md-12">
                <input id="dataNas" name="dataNas" type="text" placeholder="Data de nascimento" class="form-control input-md">
              </div>
            </div>
            <div class="form-group">
              <div class="col-md-12">
                <input id="telefone" name="telefone" type="text" placeholder="Telefone" class="form-control input-md">
              </div>
            </div>
          </fieldset>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-dismiss="modal">Fechar</button>
          <button type="submit" class="btn btn-primary" name="edit-basic-informations" id="edit-basic-informations">Ok</button>
        </div>
      </form>
    </div>
  </div>
</div>

This same code works if the element is not modal.

    
asked by anonymous 05.09.2016 / 22:38

1 answer

1

Your line

var tel = document.querySelector("input[attrname=telefone]");

It has the wrong syntax, do it as follows.

var tel = document.querySelector('input[name="telefone"]');

    
06.09.2016 / 16:48