Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 275
Susana Santos Avatar asked Oct 19 '15 20:10

Susana Santos


People also ask

How do I fix uncaught TypeError X is not a function?

The React.js "Uncaught TypeError: X is not a function" occurs when we try to call a value that is not a function as a function, e.g. calling the props object instead of a function. To solve the error, console.log the value you are calling and make sure it is a function.

How to mask an input in a jQuery script?

jQuery itself does not provide functionality for masking an input. You can use one of the plugins avaiable for it.

How do I fix the error map is not a function?

The "TypeError: map is not a function" occurs when we call the map () method on a value that is not an array. To solve the error, console.log the value you're calling the map () method on and make sure to only call map on valid arrays. Here is an example of how the error occurs. We called the Array.map () method on an object and got the error back.


3 Answers

Change this line from

$(document).ready(function(){ 

to

$(document).ready(function($){
like image 79
Martins Oyebode Avatar answered Oct 22 '22 00:10

Martins Oyebode


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.

like image 37
user3311636 Avatar answered Oct 22 '22 00:10

user3311636


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>
like image 1
Павел Еременко Avatar answered Oct 21 '22 23:10

Павел Еременко