"Automagically" fills an address form
Switch branches/tags
Clone or download
Latest commit b69d22c Nov 9, 2017
Permalink
Failed to load latest commit information.
bin first commit Apr 25, 2017
lib fix https problem Jun 14, 2017
spec first commit Apr 25, 2017
vendor/assets/javascripts success event Oct 24, 2017
.gitignore first commit Apr 25, 2017
.rspec first commit Apr 25, 2017
.travis.yml first commit Apr 25, 2017
Gemfile Gemspec Apr 26, 2017
README.md Update README.md Nov 9, 2017
Rakefile first commit Apr 25, 2017
autocomplete_zipcode.gemspec version 0.1.1 Apr 26, 2017

README.md

AutocompleteZipcode

This gem was built to "automagically" fills an address form, for Rails version >= 3.1.

Try it

HerokuApp

Installation

Add the following gems to your application's Gemfile:

gem 'autocomplete_zipcode'

And then execute:

$ bundle install

Usage

In app/assets/javascripts/application.js, you should add as follows:

//= require ...
//= require turbolinks
//= require autocomplete_zipcode

Basic Example:

<%= simple_form_for :example do |f| %>
  ...
  <%= f.input :zipcode, as: :zipcode %>
  <%= f.input :street, as: :street %>
  <%= f.input :neighborhood, as: :neighborhood %>
  <%= f.input :city, as: :city %>
  <%= f.input :state, as: :state %>
  ...
<% end %>

If you are not using simple_form, then simply add the data-provider="zipcode" and the other fields name to the input field yourself.

<%= form_for :example do |f| %>
  ...
  <%= f.text_field :zipcode, data: {provider: :zipcode} %>
  <%= f.text_field :street, data: {provider: :street}  %>
  ...
<% end %>

Handle invalid zipcodes

Simply add an event listener callback to zipcode.error, for example:

document.addEventListener('zipcode.error', function(e) {
  alert('Invalid zipcode!!!')
});

Sample projects

For an example, take a look at this repository.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request