Country
The Country field renders a Select dropdown on forms with ISO 3166-1 countries supplied by the countries gem. It stores the country code in the database and displays the country name in Avo.
# app/avo/resources/user.rb
class Avo::Resources::User < Avo::BaseResource
def fields
field :country, as: :country
end
endBy default, country names appear in the dropdown and on Index and Show views. The dropdown is sorted by country name and prompts users to choose a country.
Enable country selection
WARNING
Add the countries gem to your Gemfile so the field can load the country list.
# Gemfile
gem "countries"Display country codes instead of names
If your users work with country codes, set display_code to true. This changes the labels in the dropdown as well as the values displayed on Index and Show views. It does not change the stored code.
# app/avo/resources/user.rb
class Avo::Resources::User < Avo::BaseResource
def fields
field :country, as: :country, display_code: true
end
endOffer an empty selection
Use include_blank to control the dropdown's first, empty option. For example, give it a label that explains what leaving the country empty means:
# app/avo/resources/user.rb
class Avo::Resources::User < Avo::BaseResource
def fields
field :country, as: :country, include_blank: "No country selected"
end
endSee also the Select field's include_blank documentation.
Customize shared field behavior
For labels, help text, placeholders, visibility, and other options shared across fields, see Common field options.