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

Conversation

pmor
Copy link
Member

@pmor pmor commented Apr 11, 2022

@scudco

I've been thinking about #194 , and came up with another possibility:

country_select :user, :country_code, only: %w(CH AT DE), sort_provided: false

country_select :user, :country_code, priority_countries: %w(CH AT DE), sort_provided: false

That is, adding a sort_provided option that controls if the list of countries is locale-sorted or we use the order of the only and priority_countries array.

The default behaviour is unchanged from the current version, this just adds the new option to allow preserving the sort order as inputted, and is a pretty small code change.

This adds the new option and is a small change, but it changes the default behaviour for priority_countries to sorting the list, so that both priority_countries and only have the same sorting behaviour and defaults, so it does include a breaking change.

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

@pmor pmor marked this pull request as ready for review June 27, 2022 08:31
@pmor pmor merged commit 7e73c4c into master Jun 30, 2022
@pmor pmor deleted the custom_order_for_only_array branch June 30, 2022 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant