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.21.0 lib/avo/fields/country_field.rb
avo-2.21.1.pre.pr1476 lib/avo/fields/country_field.rb
avo-2.21.1.pre.issue1450 lib/avo/fields/country_field.rb
avo-2.21.1.pre.issue1444 lib/avo/fields/country_field.rb
avo-2.20.0 lib/avo/fields/country_field.rb
avo-2.19.0 lib/avo/fields/country_field.rb
avo-2.18.1 lib/avo/fields/country_field.rb
avo-2.18.1.pre.1.eagerloaddirs lib/avo/fields/country_field.rb
avo-2.18.0 lib/avo/fields/country_field.rb
avo-2.17.1.pre.5.stackedlayout lib/avo/fields/country_field.rb