Sha256: 0d0add4a241baba656e1725f3fb8af06e71c0a6c07e3b3350f9f5ab48183fdbd

Contents?: true

Size: 693 Bytes

Versions: 3

Compression:

Stored size: 693 Bytes

Contents

var ready = function() {
  zipcode_input = $('[data-provider="zipcode"]')
  zipcode_input.keyup(function(e){
    var zipcode = $('[data-provider="zipcode"]').val().replace(/[^0-9]/g, '');
    if(zipcode.length == 8) {
      $.get('http://viacep.com.br/ws/'+ zipcode +'/json/').then(function(response) {
        var inputs = {
          // zipcode: 'cep',
          street: 'logradouro',
          neighborhood: 'bairro',
          city: 'localidade',
          state: 'uf'
        }

        for(var key in inputs) {
          $('[data-provider="' + key + '"]').val(response[inputs[key]])
        }
      });
    };
  })
};

$(document).ready(ready);
$(document).on("turbolinks:load", ready);

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
autocomplete_zipcode-0.1.1 vendor/assets/javascripts/autocomplete_zipcode.js
autocomplete_zipcode-0.1.0 vendor/assets/javascripts/autocomplete_zipcode.js
autocomplete_zipcode-0.0.1 vendor/assets/javascripts/autocomplete_zipcode.js