How to put mask in the form input field that is in a modal window of bootstrap

1

People, I'm using the jquery mask on head

<script type="text/javascript"> 
            $( document ).ready(function() {
                $("#celular1").mask("(00) 00000-0000");
                });
            });
</script>

I'm connected to the jquery and jquery mask in the head of html, in a normal form it works but in the modal window that I'm using to register clients does not receive the mask when typing. How can I make the input to receive the mask?

    
asked by anonymous 22.12.2018 / 01:27

1 answer

0

Strange face, here in the example is working the mask inside the modal normally, see if the mask file is referenced on the page where the modal is opened:

$(function() {
  $('#tel').mask('(00) 0 0000-0000');
  $('#cep').mask('00000-000');
})
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css">

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.14.15/jquery.mask.min.js"></script>

<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
  Abrir modal
</button>

<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Modal</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <form>
          <div class="form-group">
            <label for="tel">Telefone</label>
            <input type="email" class="form-control" id="tel" aria-describedby="tel" placeholder="Telefone">
            <small id="tel" class="form-text text-muted">Digite seu telefone.</small>
          </div>
          <div class="form-group">
            <label for="cep">Cep</label>
            <input type="text" class="form-control" id="cep" placeholder="CEP">
          </div>
        </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Fechar</button>
        <button type="button" class="btn btn-primary">Salvar</button>
      </div>
    </div>
  </div>
</div>
    
22.12.2018 / 20:34