Class: Avo::Fields::CountryField
- Defined in:
- lib/avo/fields/country_field.rb
Defined Under Namespace
Classes: EditComponent, IndexComponent, ShowComponent
Instance Attribute Summary collapse
-
#countries ⇒ Object
readonly
Returns the value of attribute countries.
-
#display_code ⇒ Object
readonly
Returns the value of attribute display_code.
Attributes inherited from BaseField
#action, #as_avatar, #as_description, #as_label, #block, #computable, #computed, #computed_value, #default, #format_using, #help, #id, #model, #null_values, #nullable, #panel_name, #readonly, #required, #resource, #sortable, #updatable, #user, #view, #visible
Attributes included from FieldExtensions::VisibleInDifferentViews
#show_on_edit, #show_on_index, #show_on_new, #show_on_show
Instance Method Summary collapse
-
#initialize(id, **args, &block) ⇒ CountryField
constructor
A new instance of CountryField.
- #select_options ⇒ Object
Methods inherited from BaseField
#component_for_view, #custom?, #database_id, #fill_field, #has_own_panel?, #hydrate, #model_errors, #name, #placeholder, #resolve_attribute, #to_permitted_param, #translation_key, #type, #value, #view_component_name, #visible?
Methods included from FieldExtensions::HasFieldName
Methods included from FieldExtensions::VisibleInDifferentViews
#except_on, #hide_on, #only_on, #show_on
Constructor Details
#initialize(id, **args, &block) ⇒ CountryField
Returns a new instance of CountryField.
7 8 9 10 11 12 13 14 |
# File 'lib/avo/fields/country_field.rb', line 7 def initialize(id, **args, &block) args[:placeholder] ||= I18n.t("avo.choose_a_country") super(id, **args, &block) @countries = ISO3166::Country.translations.sort_by { |code, name| name }.to_h @display_code = args[:display_code].present? ? args[:display_code] : false end |
Instance Attribute Details
#countries ⇒ Object (readonly)
Returns the value of attribute countries.
4 5 6 |
# File 'lib/avo/fields/country_field.rb', line 4 def countries @countries end |
#display_code ⇒ Object (readonly)
Returns the value of attribute display_code.
5 6 7 |
# File 'lib/avo/fields/country_field.rb', line 5 def display_code @display_code end |
Instance Method Details
#select_options ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/avo/fields/country_field.rb', line 16 def if @display_code countries.map do |code, name| [code, code] end else countries.map do |code, name| [name, code] end end end |