Sha256: edb2df5000b6c0f13723742a2e545711c604c459e5e500ceeeb0d4a806f7b5f8

Contents?: true

Size: 898 Bytes

Versions: 90

Compression:

Stored size: 898 Bytes

Contents

module Avo
  module Fields
    class CountryField < BaseField
      include Avo::Fields::FieldExtensions::HasIncludeBlank

      attr_reader :countries
      attr_reader :display_code

      def initialize(id, **args, &block)
        args[:placeholder] ||= I18n.t("avo.choose_a_country")

        super(id, **args, &block)

        @countries = begin
          ISO3166::Country.translations.sort_by { |code, name| name }.to_h
        rescue
          {none: "You need to install the countries gem for this field to work properly"}
        end
        @display_code = args[:display_code].present? ? args[:display_code] : false
      end

      def select_options
        if @display_code
          countries.map do |code, name|
            [code, code]
          end
        else
          countries.map do |code, name|
            [name, code]
          end
        end
      end
    end
  end
end

Version data entries

90 entries across 90 versions & 1 rubygems

Version Path
avo-2.36.2 lib/avo/fields/country_field.rb
avo-2.36.1 lib/avo/fields/country_field.rb
avo-2.36.0 lib/avo/fields/country_field.rb
avo-2.35.0 lib/avo/fields/country_field.rb
avo-2.34.7.pre.1 lib/avo/fields/country_field.rb
avo-2.34.6 lib/avo/fields/country_field.rb
avo-2.34.5 lib/avo/fields/country_field.rb
avo-2.34.4 lib/avo/fields/country_field.rb
avo-2.34.4.pre.1 lib/avo/fields/country_field.rb
avo-2.34.3 lib/avo/fields/country_field.rb
avo-2.34.2 lib/avo/fields/country_field.rb
avo-2.34.1 lib/avo/fields/country_field.rb
avo-2.34.0 lib/avo/fields/country_field.rb
avo-2.33.3 lib/avo/fields/country_field.rb
avo-2.33.3.pre.2 lib/avo/fields/country_field.rb
avo-2.33.3.pre.1 lib/avo/fields/country_field.rb
avo-2.33.2 lib/avo/fields/country_field.rb
avo-2.33.1 lib/avo/fields/country_field.rb
avo-2.33.0 lib/avo/fields/country_field.rb
avo-2.32.6 lib/avo/fields/country_field.rb