Commit ec0ccc2217031585bb4c253d0f2e6b2cb0840c97
1 parent
44f65db0
Exists in
master
and in
5 other branches
Mask to cpf field #55
Showing
2 changed files
with
154 additions
and
17 deletions
Show diff stats
@@ -0,0 +1,129 @@ | @@ -0,0 +1,129 @@ | ||
1 | +function campoNumerico(campo, evento){ | ||
2 | + var codTecla; | ||
3 | + var tamanho; | ||
4 | + | ||
5 | + if( document.all ) {// Internet Explorer | ||
6 | + codTecla = evento.keyCode; | ||
7 | + } else if( document.layers ) { // Nestcape | ||
8 | + codTecla = evento.which; | ||
9 | + } | ||
10 | + else if( evento) { // Firefox | ||
11 | + codTecla = evento.which; | ||
12 | + } | ||
13 | + if( (codTecla > 47 && codTecla < 58) || codTecla==8 || codTecla == 0){ | ||
14 | + return true; | ||
15 | + } else { | ||
16 | + evento.returnValue = false; | ||
17 | + return false; | ||
18 | + } | ||
19 | +} | ||
20 | + | ||
21 | +function formatarCpf(campo, evento){ | ||
22 | + var codTecla; | ||
23 | + var tamanho; | ||
24 | + if( document.all ) { // Internet Explorer | ||
25 | + codTecla = evento.keyCode; | ||
26 | + } else if( document.layers ) { // Nestcape | ||
27 | + codTecla = evento.which; | ||
28 | + } | ||
29 | + else if( evento ) { // Firefox | ||
30 | + codTecla = evento.which; | ||
31 | + } | ||
32 | + tamanho = campo.value.length; | ||
33 | + if( (codTecla > 47 && codTecla < 58) || codTecla== 8 || codTecla == 0){ | ||
34 | + if(tamanho < 14 ){ | ||
35 | + if( tamanho == 3 && codTecla != 8 && codTecla != 0){ | ||
36 | + campo.value = campo.value + "."; | ||
37 | + }else if( tamanho == 7 && codTecla != 8 && codTecla != 0){ | ||
38 | + campo.value = campo.value + "."; | ||
39 | + }else if( tamanho == 11 && codTecla != 8 && codTecla != 0){ | ||
40 | + campo.value = campo.value + "-"; | ||
41 | + } | ||
42 | + }else{ | ||
43 | + evento.returnValue = false; | ||
44 | + } | ||
45 | + return true; | ||
46 | + } else { | ||
47 | + return false; | ||
48 | + } | ||
49 | + return false; | ||
50 | +} | ||
51 | + | ||
52 | +function validarCpfSemAlert(campo,nome,idElementoMensagemErro){ | ||
53 | + //alert("teste"); | ||
54 | + cpf = campo.value; | ||
55 | + | ||
56 | + cpf = cpf.replace(".",""); | ||
57 | + cpf = cpf.replace("-",""); | ||
58 | + cpf = cpf.replace(".",""); | ||
59 | + retorno = true; | ||
60 | + | ||
61 | + if(trim(cpf).length > 0){ | ||
62 | + //alert("teste2"); | ||
63 | + cpfstr= ''; | ||
64 | + temp = cpf + ''; | ||
65 | + | ||
66 | + cpfstr = temp.substring(0,3); | ||
67 | + cpfstr = cpfstr + temp.substring(3,6); | ||
68 | + cpfstr = cpfstr + temp.substring(6,9); | ||
69 | + cpfstr = cpfstr + temp.substring(9,11); | ||
70 | + | ||
71 | + | ||
72 | + | ||
73 | + retorno = false; | ||
74 | + if(cpf != null){ | ||
75 | + //alert("teste3"); | ||
76 | + soma = 0; | ||
77 | + digito1 = 0; | ||
78 | + digito2 = 0; | ||
79 | + for(i = 0; i < 9; i = i + 1) { | ||
80 | + soma = soma + ((parseInt(cpf.substring(i,i+1)))*(11-(i+1))); | ||
81 | + } | ||
82 | + soma = soma % 11; | ||
83 | + if (soma == 0 || soma == 1) { | ||
84 | + digito1 = 0; | ||
85 | + } else { | ||
86 | + digito1 = 11 - soma; | ||
87 | + } | ||
88 | + soma = 0; | ||
89 | + | ||
90 | + for(i = 0; i < 9; i = i + 1) { | ||
91 | + soma = soma + ((parseInt(cpf.substring(i,i+1)))*(12-(i+1))); | ||
92 | + } | ||
93 | + soma = soma + (digito1*2); | ||
94 | + soma = soma % 11; | ||
95 | + if (soma == 0 || soma == 1) { | ||
96 | + digito2 = 0; | ||
97 | + } | ||
98 | + else{ | ||
99 | + digito2 = 11 - soma; | ||
100 | + } | ||
101 | + digito = digito1 +''+ digito2; | ||
102 | + | ||
103 | + | ||
104 | + //alert(cpfstr.substring(9,11)); | ||
105 | + if(digito == (cpfstr.substring(9,11))){ | ||
106 | + retorno = true; | ||
107 | + } else{ | ||
108 | + //alert("teste4"); | ||
109 | + retorno = false; | ||
110 | + | ||
111 | + } | ||
112 | + } else { | ||
113 | + retorno = false; | ||
114 | + } | ||
115 | + }else{ | ||
116 | + retorno = false; | ||
117 | + } | ||
118 | + //alert(retorno); | ||
119 | + if(retorno == false){ | ||
120 | + //alert('E-mail informado invalido! Por favor, especifique um E-mail válido para o campo \"' + nome + '\".'); | ||
121 | + document.getElementById(idElementoMensagemErro).style.display = ''; | ||
122 | + campo.focus(); | ||
123 | + return false; | ||
124 | + }else{ | ||
125 | + document.getElementById(idElementoMensagemErro).style.display = 'none'; | ||
126 | + return true; | ||
127 | + } | ||
128 | + return retorno; | ||
129 | +} | ||
0 | \ No newline at end of file | 130 | \ No newline at end of file |
users/templates/users/create.html
@@ -14,6 +14,7 @@ | @@ -14,6 +14,7 @@ | ||
14 | 14 | ||
15 | 15 | ||
16 | {% block content %} | 16 | {% block content %} |
17 | + <script src="{% static 'js/base/amadeus.js' %}"></script> | ||
17 | {% if messages %} | 18 | {% if messages %} |
18 | {% for message in messages %} | 19 | {% for message in messages %} |
19 | <div class="alert alert-success alert-dismissible" role="alert"> | 20 | <div class="alert alert-success alert-dismissible" role="alert"> |
@@ -33,30 +34,33 @@ | @@ -33,30 +34,33 @@ | ||
33 | {% for field in form %} | 34 | {% for field in form %} |
34 | <div class="form-group{% if form.has_error %} has-error {% endif %} is-fileinput"> | 35 | <div class="form-group{% if form.has_error %} has-error {% endif %} is-fileinput"> |
35 | {% if field.auto_id == 'id_birth_date' %} | 36 | {% if field.auto_id == 'id_birth_date' %} |
36 | - <label for="{{ field.auto_id }}">{{ field.label }}</label> | 37 | + <label for="{{ field.auto_id }}">{{ field.label }}</label> |
37 | <input type="date" class="form-control"name="{{field.name}}" value="{% if field.value.year %}{{field.value|date:'Y-m-d'}}{% else %}{{field.value}}{% endif %}"> | 38 | <input type="date" class="form-control"name="{{field.name}}" value="{% if field.value.year %}{{field.value|date:'Y-m-d'}}{% else %}{{field.value}}{% endif %}"> |
38 | {% elif field.auto_id == 'id_image' %} | 39 | {% elif field.auto_id == 'id_image' %} |
39 | - <label for="{{ field.auto_id }}">{{ field.label }}</label> | 40 | + <label for="{{ field.auto_id }}">{{ field.label }}</label> |
40 | {% render_field field class='form-control' %} | 41 | {% render_field field class='form-control' %} |
41 | <div class="input-group"> | 42 | <div class="input-group"> |
42 | - <input type="text" readonly="" class="form-control" placeholder="{% trans 'Choose your photo...' %}"> | ||
43 | - <span class="input-group-btn input-group-sm"> | ||
44 | - <button type="button" class="btn btn-fab btn-fab-mini"> | ||
45 | - <i class="material-icons">attach_file</i> | ||
46 | - </button> | ||
47 | - </span> | ||
48 | - </div> | ||
49 | - {% elif field.auto_id == 'id_is_staff' or field.auto_id == 'id_is_active' %} | ||
50 | - <div class="checkbox"> | ||
51 | - <label> | ||
52 | - <input type="checkbox" name="checkbox"><span class="checkbox-material"><span class="check"></span></span> {{field.label}} | ||
53 | - </label> | ||
54 | - </div> | 43 | + <input type="text" readonly="" class="form-control" placeholder="{% trans 'Choose your photo...' %}"> |
44 | + <span class="input-group-btn input-group-sm"> | ||
45 | + <button type="button" class="btn btn-fab btn-fab-mini"> | ||
46 | + <i class="material-icons">attach_file</i> | ||
47 | + </button> | ||
48 | + </span> | ||
49 | + </div> | ||
50 | + {% elif field.auto_id == 'id_is_staff' or field.auto_id == 'id_is_active' %} | ||
51 | + <div class="checkbox"> | ||
52 | + <label> | ||
53 | + <input type="checkbox" name="checkbox"><span class="checkbox-material"><span class="check"></span></span> {{field.label}} | ||
54 | + </label> | ||
55 | + </div> | ||
56 | + {% elif field.auto_id == 'id_cpf' %} | ||
57 | + <label for="{{ field.auto_id }}">{{ field.label }}</label> | ||
58 | + {% render_field field class='form-control' onkeypress='campoNumerico(this,event); formatarCpf(this,event);' %} | ||
55 | {% else %} | 59 | {% else %} |
56 | - <label for="{{ field.auto_id }}">{{ field.label }}</label> | 60 | + <label for="{{ field.auto_id }}">{{ field.label }}</label> |
57 | {% render_field field class='form-control' %} | 61 | {% render_field field class='form-control' %} |
58 | {% endif %} | 62 | {% endif %} |
59 | - <span id="helpBlock" class="help-block">{{ field.help_text }}</span> | 63 | + <span id="helpBlock" class="help-block">{{ field.help_text }}</span> |
60 | {% if field.errors.length > 0 %} | 64 | {% if field.errors.length > 0 %} |
61 | <div class="alert alert-danger alert-dismissible" role="alert"> | 65 | <div class="alert alert-danger alert-dismissible" role="alert"> |
62 | <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | 66 | <button type="button" class="close" data-dismiss="alert" aria-label="Close"> |
@@ -85,3 +89,7 @@ | @@ -85,3 +89,7 @@ | ||
85 | </br> | 89 | </br> |
86 | </br> | 90 | </br> |
87 | {% endblock %} | 91 | {% endblock %} |
92 | + | ||
93 | +{% block javascript %} | ||
94 | + | ||
95 | +{% endblock %} |