Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 25 additions & 18 deletions view/frontend/templates/address/edit.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samuelmafra isso não removeria outras máscaras adicionadas por outros módulos usando outros patterns via jquery? #duvida

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acredito que para o módulo ter suporte corretamente para multi-idiomas precise de bem mais ajustes...

}
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();
}
});
}
});
});
</script>
</script>