Mask using flask does not load

Asked

Viewed 285 times

0

This is the header:

<script src="{{ url_for('static', filename='jquery-2.1.4.min.js') }}"></script>
<script src="{{ url_for('static', filename='main.js') }}"></script></script>

This is the field code I want to put the CPF mask (000,000,000-00):

         <div class="col-sm-4">
            <strong>{{ perfilForm.CPF.label }}</strong>  
            {{ perfilForm.CPF(class_="form-control", value=meuPerfil.CPF) }}
          </div>

Inside the main.js I have this structure:

$(document).ready( function () {
    $('#CPF').mask('000.000.000-00');
} );

However it does not enter at the moment I enter the numbers. Someone can give me the hint?

  • Hello Philip! Took a look at the console to see if it shows any errors?

1 answer

0


Are you using the jQuery Mask which is not an integral part of jQuery and therefore needs to be loaded as well. By the way, is that "_=" correct? This example using pure HTML worked:

<html>
  <body>
    <input type='text' class="form-control" id='cpf'>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
    <script src="jquery.mask.js"></script>
    <script>
$(document).ready(function (){
  $('#cpf').mask('000.000.000-00');
});
    </script>
  </body>
</html>
  • Yes, the class_= is how you define custom classes in wtforms

  • Added the jQuery before the jQuery Mask and it worked! Thanks!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.