Skip to content

Commit

Permalink
adicionado mascara no telefone no checkout
Browse files Browse the repository at this point in the history
  • Loading branch information
LimaJonas committed May 19, 2021
1 parent 687296e commit ff11ae4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

- Simples solução para mascarar campos automaticamente no Magento2.
- Funcionando nos campos de CPF/CNPJ (TAX/VAT), Telefone, e CEP (Zipcode/Postcode).
- Usando [jQuerySimpleMas](https://github.com/DevUtils/jQuerySimpleMask "jQuerySimpleMas") adaptado para o Magento2.
- Usando [jQuerySimpleMask](https://github.com/DevUtils/jQuerySimpleMask "jQuerySimpleMas") adaptado para o Magento2.
- Testado e criado usando Magento 2.3.6
### Instalação (Apenas manual)
- Faça o [download](https://github.com/LimaJonas/magento-maskinput/releases "download") do modulo.
Expand Down
32 changes: 30 additions & 2 deletions view/frontend/web/js/setMask.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require(['jquery', 'jquery/ui'], function($){

// ============================================
// CEP na página de usuário
$('#zip').simpleMask({
'mask': ['########']
Expand All @@ -11,7 +11,7 @@ require(['jquery', 'jquery/ui'], function($){
'mask': ["########"]
});
});

// ============================================
// Telefone Celular/Fixo
// Essa função verifica quantos números estão digitado para saber qual máscara usar, também usada no CPF/CNPJ.
$("#telephone").keydown(function(){
Expand Down Expand Up @@ -41,6 +41,34 @@ require(['jquery', 'jquery/ui'], function($){
$(this).val(currentValue);
});

// Telene Celular/Fixo no Checkout
$(document).on("keydown",'input[name="telephone"]', function() {
try {
$('input[name="telephone"]').unmask();
} catch (e) {}
var tamanho = $('input[name="telephone"]').val().length;

if(tamanho > 13){
$('input[name="telephone"]').simpleMask({
'mask': ["(##) #####-####"] //Telefone Celular
});
} else{
$('input[name="telephone"]').simpleMask({
'mask': ["(##) ####-####"] //Telefone Fixo
});
}
// ajustando foco
var elem = this;
setTimeout(function(){
// mudo a posição do seletor
elem.selectionStart = elem.selectionEnd = 10000;
}, 0);
// reaplico o valor para mudar o foco
var currentValue = $(this).val();
$(this).val('');
$(this).val(currentValue);
});
// ============================================
// CPF/CNPJ
$("#taxvat").keydown(function(){
try {
Expand Down

0 comments on commit ff11ae4

Please sign in to comment.