What's an easy way to share EctoEnum type with templates in forms select input?

Just massage your enum_map return of [registered: 0, active: 1, inactive: 2, archived: 3] into the right format, like this: :slight_smile:

iex> [registered: 0, active: 1, inactive: 2, archived: 3] |> Enum.map(&to_string(elem(&1, 0)))
["registered", "active", "inactive", "archived"]

Although the html should accept atoms so the to_string step should not be necessary in any case. :slight_smile:

Honestly for enum’s though I like to use PostgreSQL Enumerations instead, can store things so they look like strings and get them back the same, but only accepts the subset. :slight_smile:

2 Likes