From 3a1c9897ad8ca8660be17042daccd9db2342a6a8 Mon Sep 17 00:00:00 2001 From: samuelmafra Date: Wed, 26 Sep 2018 14:55:35 -0300 Subject: [PATCH] =?UTF-8?q?Corre=C3=A7=C3=B5es=20diversas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A cada keyup no campo postcode: 1 - Verifica se o país selecionado é Brasil para aplicar ou remover a máscara 2 - Verifica se a quantidade de número é igual a 8 e se o país selecionado é Brasil para a requisição ajax 3 - Adiciona focus no campo street_2 (número) se a requisição for bem sucedida --- view/frontend/templates/address/edit.phtml | 43 +++++++++++++--------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/view/frontend/templates/address/edit.phtml b/view/frontend/templates/address/edit.phtml index eda4be5..e7056a0 100755 --- a/view/frontend/templates/address/edit.phtml +++ b/view/frontend/templates/address/edit.phtml @@ -147,23 +147,30 @@ 'inputMask', 'mage/url' ], function ($, mask, url) { - $("#postcode").mask('00000-000', {clearIfNotMatch: true}); - $('#postcode').change(function(){ - zipcode = $(this).val().replace('-', ''); - var ajaxurl = url.build("brcustomer/consult/address/zipcode/"+zipcode); - - $.getJSON(ajaxurl, null, function(data) { - if(data.error){ - // TODO - }else{ - $("#street_1").val(data.street); - $("#street_3").val(data.neighborhood); - $("#street_4").val(data.complement); - $("#city").val(data.city); - $("#country").val('BR'); - $("#region_id").val(data.uf); - } - }); + $('#postcode').keyup(function(){ + var country = jQuery("[name=country_id]").val() + if (country=='BR') { + $("#postcode").mask('00000-000', {clearIfNotMatch: true}); + } else { + jQuery('#'+this.uid).unmask(); + } + var zipcode = $(this).val().replace('-', ''); + if(zipcode.length == 8 && country =='BR'){ + var ajaxurl = url.build("brcustomer/consult/address/zipcode/"+zipcode); + $.getJSON(ajaxurl, null, function(data) { + if(data.error){ + // TODO + }else{ + $("#street_1").val(data.street); + $("#street_3").val(data.neighborhood); + $("#street_4").val(data.complement); + $("#city").val(data.city); + $("#country").val('BR'); + $("#region_id").val(data.uf); + $("#street_2").focus(); + } + }); + } }); }); - \ No newline at end of file +