maskedinput Uncaught TypeError: $(...).mask is not a function

Susana Santos picture Susana Santos · Oct 19, 2015 · Viewed 34.4k times · Source

Good afternoon On my there is

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" src="{{ asset('bundles/reflorestasite/js/jquery.maskedinput.min.js') }}"></script>
<script type="text/javascript" src="{{ asset('bundles/reflorestasite/js/validacoes.js') }}"></script>
<script type="text/javascript" src="{{ asset_url }}"></script>

And on "validacoes.js" file there is

$(document).ready(function(){

  $(".cpf").mask("999.999.999-99");
  $('.cpf').blur(function () {
    var id=$(this).attr("id");
    var val=$(this).val();
    var pattern = new RegExp(/[0-9]{3}[\.]?[0-9]{3}[\.]?[0-9]{3}[-]?[0-9]{2}/);

    if(val.match(pattern) == null){
      $("#"+id+"_error").html("Digite um CPF válido");
    }
  });
});

I've already verifed at console and all javascript files are there. However i'm getting the error "Uncaught TypeError: $(...).mask is not a function"

Does anyone has a clue why symfony is not recognizing the maskedinput plugin?

Thankyou very much.

Answer

Martins Oyebode picture Martins Oyebode · Oct 21, 2015

Change this line from

$(document).ready(function(){ 

to

$(document).ready(function($){