
Security News
Astral Launches pyx: A Python-Native Package Registry
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
autocomplete_zipcode
Advanced tools
This gem was built to "automagically" fills an address form, for Rails version >= 3.1.
Add the following gems to your application's Gemfile:
gem 'autocomplete_zipcode'
And then execute:
bundle install
In app/assets/javascripts/application.js, you should add as follows:
// app/assets/javascripts/application.js
//= require ...
//= require turbolinks
//= require jquery
//= require autocomplete_zipcode
$(document).on('ready', () => {
AutocompleteZipcode.mount();
});
<%= 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: { autocomplete_zipcode_provider: :zipcode } %>
<%= f.text_field :street, data: { autocomplete_zipcode_provider: :street } %>
...
<% end %>
Simply add an event listener callback to zipcode.error
, for example:
// app/assets/javascripts/application.js
document.addEventListener('zipcode.error', () => {
alert('Invalid zipcode!!!')
});
// app/assets/javascripts/application.js
//= require ...
//= require turbolinks
//= require jquery
//= require autocomplete_zipcode
$(document).on('ready', () => {
AutocompleteZipcode.mount({
onSuccess: (containerEl, zipcodeEl) => {
console.log(containerEl, zipcodeEl);
},
onFail: (containerEl, zipcodeEl) => {
console.log(containerEl, zipcodeEl);
},
});
document.addEventListener('zipcode.success', () => {
console.log('zipcode fetched successfully');
});
document.addEventListener('zipcode.error', () => {
console.log('zipcode fetch failed');
});
});
For an online example, take a look at this repository.
You can also see it working on the dummy application (spec/dummy
)
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)FAQs
Unknown package
We found that autocomplete_zipcode demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.
Security News
The latest Opengrep releases add Apex scanning, precision rule tuning, and performance gains for open source static code analysis.