|
ATTENTION: This will not work if you put your add and edit page to "SHOW IN POPUP" option
Atenção: Isto não vai funcionar se voce escolher para que suas paginas de adicionar e editar sejam abertas em popup. I have solved that problem and will share with all, because i know "Brazilians need it".
Portuguese: Eu resolvi o problema, porque sei que todos os brasileiros precisam disso. First... do that: http://www.asprunner.com/forums/topic/16037-veja-como-adicionar-mascara-no-campo-com-phprunner-53/
Portuguese: Primeiro faça o que esta no link acima. Thanks to Erich. Your cpf_cnpj field need to stay with this name: cpf_cnpj (for this tutorial works)
Portuguese: Seu campo cpf_cnpj precisa ter este nome... cpf_cnpj Add a field in your form called: fisica_juridica (for do that, create a new row in your customers database... fisica_juridica tinyint(4) DEFAULT NULL )
Portuguese: Adicione um campo em seu formulário chamado fisica_juridica (Para fazer isto, crie uma nova linha em seu banco de dados de clientes... fisica_juridica tinyint(4) DEFAULT NULL ) now, create another table
Portuguese: agora crie mais uma tabela dentro de seu banco de dados
CREATE TABLE `config_fis_jur` (
`cod_fis_jur` int(2) NOT NULL AUTO_INCREMENT,
`tipo` varchar(10) DEFAULT NULL,
PRIMARY KEY (`cod_fis_jur`)
) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; -- ----------------------------
-- Records
-- ----------------------------
INSERT INTO `config_fis_jur` VALUES ('1', 'Fisica');
INSERT INTO `config_fis_jur` VALUES ('2', 'Juridica');
Go to your project in phprunner and put the field fisica_juridica with Radio Button, lookup table, table: config_fis_jur, link field: cod_fis_jur, display field: tipo and mark horizontal layout if you want.
Portuguese: No seu phprunner vá até seu projeto e coloque o novo campo fisica_juridica como Radio Button, lookup table, table: config_fis_jur, link field: cod_fis_jur, display field: tipo e marque a opção horizontal layout para ficar com um visual melhor. Create a new file called: pass_cpf.js
Portuguese: Crie um novo arquivo chamado: pass_cpf.js
function pass_cpf(value, element) {
if (value.length < 15){ //it´s 15 because get characters of mask too
value = value.replace('.','');
value = value.replace('.','');
cpf = value.replace('-','');
while(cpf.length < 11) cpf = "0"+ cpf;
var expReg = /^0+$|^1+$|^2+$|^3+$|^4+$|^5+$|^6+$|^7+$|^8+$|^9+$/;
var a = [];
var b = new Number;
var c = 11;
for (i=0; i<11; i++){
a[i] = cpf.charAt(i);
if (i < 9) b += (a[i] * --c);
}
if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11-x }
b = 0;
c = 11;
for (y=0; y<10; y++) b += (a[y] * c--);
if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11-x; }
if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10]) || cpf.match(expReg)) return 'CPF ou CNPJ Invalido';
return true;
}else{
cnpj = value.replace(/\D/g,"");
while(cnpj.length < 14) cnpj = "0"+ cnpj;
var expReg = /^0+$|^1+$|^2+$|^3+$|^4+$|^5+$|^6+$|^7+$|^8+$|^9+$/;
var a = [];
var b = new Number;
var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
for (i=0; i<12; i++){
a[i] = cnpj.charAt(i);
b += a[i] * c[i+1];
}
if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11-x }
b = 0;
for (y=0; y<13; y++) {
b += (a[y] * c[y]);
}
if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11-x; }
if ((cnpj.charAt(12) != a[12]) || (cnpj.charAt(13) != a[13]) || cnpj.match(expReg)) return 'CPF ou CNPJ Invalido';
return true;
};
};
Now, copy this file to your C:\PHPRUNNER INSTALATION PATH\source\include\validate
Portuguese: Agora copie este arquivo para C:\PHPRUNNER INSTALATION PATH\source\include\validate Go to your phprunner editor and put the field cpf_cnpj to type text and validate as pass_cpf (if you do all things, it will appear in your validate as panel).
Portuguese: Va no editor de seu phprunner, e coloque o campo cpf_cnpj como tipo texto e validate as escolha a opção pass_cpf (se voce fez tudo certo, esta opção vai aparecer la). In the JavaScript OnLoad event put this
Portuguese: No Javascript onload event, coloque isto:
$(document).ready(function(){//Equivalente ao window.onload porem mais rapido
$("input[name=value_cpf_cnpj_1]").mask("999.999.999-99",{placeholder:'_'});//Inicia o campo como CPF
$("input[name=radio_fisica_juridica_1]:radio").change(function(){
$('input[name=value_cpf_cnpj_1]').unmask();//Remove a mascara
if($(this).val()=="1"){//Acaso seja CPF
$("input[name=value_cpf_cnpj_1]").mask("999.999.999-99",{placeholder:'_'});
} else {//Acaso seja Cnpj
$("input[name=value_cpf_cnpj_1]").mask("99.999.999/9999-99",{placeholder:'_'});
}
})
});
Build the aplication.. and BE HAPPY! =P
Portuguese: Clique novamente no build, e SEJA FELIZ. It´s get 2 full days for i do that. AND I SHARE =P. IM A GOOD PERSON!
Portuguese: 2 dias de sofrimento, tentando tudo que era possivel para fazer isto... e estou compartilhando meu trabalho. Eu sou um cara legal =P Sorry about the bad english, and i belive this will help you!
Portuguese: Desculpem pelo ingles ruim. (e o portugues também). Foda-se, não sou professor de linguas mesmo =P
|