Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow option to preserve the sort order as inputted in the only array of countries #202

Merged
merged 3 commits into from
Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/country_select/defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module CountrySelect
locale: nil,
only: nil,
priority_countries: nil,
priority_countries_divider: "-" * 15
priority_countries_divider: "-" * 15,
sort_only: true
}
end
4 changes: 2 additions & 2 deletions lib/country_select/tag_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ def format
end

def country_options
country_options_for(all_country_codes, true)
country_options_for(all_country_codes, @options.fetch(:sort_only, ::CountrySelect::DEFAULTS[:sort_only]))
end

def all_country_codes
codes = ISO3166::Country.codes

if only_country_codes.present?
codes & only_country_codes
only_country_codes & codes
Copy link
Member Author

@pmor pmor Apr 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For clarity, the swapping the order of the arrays here is what preserves the order of the only array. The new option is there to control if the final output is sorted by country_options_for or not

elsif except_country_codes.present?
codes - except_country_codes
else
Expand Down