9

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.

Susana Santos
  • 312
  • 1
  • 6
  • 18
  • Are you sure the jquery.maskedinput.min.js is being loaded in your page? [Sample fiddle here](http://jsfiddle.net/3g8gdysv/) shows your code to be working outside of symfony2 framework so you have a missing file or bad path or filename – smcd Oct 19 '15 at 21:30
  • yes I'm sure. I've looked into the source-code through google chrome and I was able to open the masked input file by clicking on it. – Susana Santos Oct 20 '15 at 21:16

3 Answers3

21

Change this line from

$(document).ready(function(){ 

to

$(document).ready(function($){
skrrgwasme
  • 9,358
  • 11
  • 54
  • 84
Martins Oyebode
  • 226
  • 2
  • 2
  • 1
    i had the same error and your solution worked, can you please explain what is the difference between two? – Çağdaş Umay Dec 07 '15 at 09:55
  • I appreciate the suggestion however this did not resolve my issue of ".mask is not a function" – Catto Jun 29 '16 at 19:37
  • Sorry it took me so long to see your answer. I marked as correct because it solved the problem to cagdasumay and I pretty sure it would solve my problem as well If I had seen it that time. Thank you very much. – Susana Santos Jul 05 '16 at 19:44
  • 1
    If you're using `jQuery.noConflict()`, be sure to use this instead: `$(document).ready(function(jQuery){` – Justin Russell Aug 09 '16 at 16:03
  • ?! can anybody explain why does this work now? I used $(function(){} before. – CodeToLife Jun 25 '20 at 13:11
3

I got this same error too, but in my case I forgot to import maskedinput.min.js

<script src="/js/jquery.maskedinput.min.js" type="text/javascript"></script>

And I was searching Google for a solution haha.

1

I solved my problem, I had to remove duplicate script connections

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript" src="/js/jquery.maskedinput-1.3.min.js"></script>