Select field with all country codes

You can create a country Select control with all countries with the countries library as follows:

def get_country_codes do
      Enum.group_by(Countries.all, &(List.to_string(&1.region)), fn(x) -> {List.to_string(x.name), List.to_string(x.alpha2)} end )
      |> Enum.into( %{}, fn {key, list} -> {key, Enum.sort(list)} end)
end

Note that Countries.all returns single-quoted char lists, which causes errors from the Select control, which expects atoms, strings or integers, hence the cast to string. Using Enum.into sorts by the keys in the list.

There’s a lot to unpack with this if you’re new to Elixir. Hope it helps!