I am upgrading/migrating older Liveview form selects to the new Core Component format
old
<div class="form-control">
<%= label f, :theme, class: "label-text" %>
<%= select(f, :theme, FolkbotWeb.WebsiteView.theme_options(), class: "select select-bordered w-full max-w-xs") %>
<%= error_tag f, :theme %>
</div>
and FolkbotWeb.WebsiteView.theme_options()
def theme_options do
WebsiteThemes.__enum_map__()
|> Enum.map(fn {k, _v} -> {String.capitalize(Atom.to_string(k)), k} end)
end
now, form_component.ex
<div>
<.header>
<%= @title %>
<:subtitle>Use this form to manage website records in your database.</:subtitle>
</.header>
<.simple_form
for={@form}
id="website-form"
phx-target={@myself}
phx-change="validate"
phx-submit="save"
>
<.input field={@form[:theme]} type="select" options="FolkbotWeb.WebsiteView.theme_options()" label="Theme" />
<:actions>
<.button phx-disable-with="Saving...">Save Website</.button>
</:actions>
</.simple_form>
</div>
"""
end
gives error
protocol Enumerable not implemented for "FolkbotWeb.WebsiteView.theme_options()" of type BitString. This protocol is implemented for the following type(s): DBConnection.PrepareStream, DBConnection.Stream, Date.Range, Ecto.Adapters.SQL.Stream, File.Stream, Function, GenEvent.Stream, HashDict, HashSet, IO.Stream, Jason.OrderedObject, List, Map, MapSet, Phoenix.LiveView.LiveStream, Postgrex.Stream, Range, Stream, Timex.Interval
obviously I am missing the LiveView Streams does not do enumerables piece Phoenix 1.7.0 final is out!