Skip to content

ricardoruwer/Cep

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Auto-fill the address by the ZIP code.

  • Built with Vanilla JS.
  • Uses ViaCEP webservice.
  • Works well when state and city is <input> or <select> (with or without ajax).

How to use

Create your form:

<form id="form">
  <input type="text" class="js-cep" placeholder="CEP">
  <input type="text" class="js-street" placeholder="Logradouro">
  <input type="text" class="js-complement" placeholder="Complemento">
  <input type="text" class="js-neighborhood" placeholder="Bairro">
  <input type="text" class="js-state" placeholder="Estado">
  <input type="text" class="js-city" placeholder="Cidade">
</form>

Include the .js file:

<script src="cepfill.js"></script>

Call the script:

<script>
  var cep = new Cep("#form");
</script>

Options

How to use:

//My Personal Options
var options = {
  cepInput:           ".js-cep", //default
  streetInput:        ".js-street", //default
  complementInput:    ".js-complement", //default
  neighborhoodInput:  ".js-neighborhood", //default
  stateInput:         ".js-state", //default
  cityInput:          ".js-city", //default
  onError: function() {
    alert("That zip code doesn't exists!");
  },
  onSuccess: function() {
    console.log("Zip code found!");
  }
}

//Call the Script
var cep = new Cep("#form", options);

Demo

codepen.io/ricardoruwer/full/ONaYBb

About

Auto-fill the address by the ZIP code.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published