Yes, there is, but slightly different version. I’m using {:phoenix_live_view, “~> 0.18.3”},
def input(%{field: {f, field}} = assigns) do
assigns
|> assign(field: nil)
|> assign_new(:name, fn ->
name = Phoenix.HTML.Form.input_name(f, field)
if assigns.multiple, do: name <> "[]", else: name
end)
|> assign_new(:id, fn -> Phoenix.HTML.Form.input_id(f, field) end)
|> assign_new(:value, fn -> Phoenix.HTML.Form.input_value(f, field) end)
|> assign_new(:errors, fn -> translate_errors(f.errors || [], field) end)
|> input()
end
I have added your version too, but still not works. The error seems related to postgresql because sometimes the error message below shown when routing to a form_component.
[error] #PID<0.1420.0> running Phoenix.Endpoint.SyncCodeReloadPlug (connection #PID<0.1339.0>, stream id 3) terminated
Server: localhost:4000 (http)
Request: GET /demographics
** (exit) an exception was raised:
** (Protocol.UndefinedError) protocol Phoenix.Param not implemented for {"demographics-1", %Market.Survey.Demographic{__meta__: #Ecto.Schema.Metadata<:loaded, "demographics">, id: 1, gender: "prefer not to say", year_of_birth: 1989, user_id: 2, user: #Ecto.Association.NotLoaded<association :user is not loaded>, inserted_at: ~N[2023-04-12 13:10:21], updated_at: ~N[2023-04-12 13:10:21]}} of type Tuple. This protocol is implemented for the following type(s): Any, Atom, BitString, Float, Integer, Map
(phoenix 1.7.2) lib/phoenix/param.ex:125: Phoenix.Param.Any.to_param/1
(market 0.1.0) lib/market_web/components/core_components.ex:475: anonymous fn/4 in MarketWeb.CoreComponents."table (overridable 1)"/1
(elixir 1.14.2) lib/enum.ex:4307: anonymous fn/3 in Enum.reduce/3
(phoenix_live_view 0.18.18) lib/phoenix_live_view/live_stream.ex:69: Enumerable.Phoenix.LiveView.LiveStream.do_reduce/3
(elixir 1.14.2) lib/enum.ex:4307: Enum.reduce/3
(market 0.1.0) lib/market_web/components/core_components.ex:474: anonymous fn/2 in MarketWeb.CoreComponents."table (overridable 1)"/1
(market 0.1.0) /Users/x/market/lib/market_web/live/demographic_live/temp_auto_generated/index.html.heex:10: MarketWeb.DemographicLive.Index.render/1
(elixir 1.14.2) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
(phoenix_live_view 0.18.18) lib/phoenix_live_view/diff.ex:396: Phoenix.LiveView.Diff.traverse/7
(phoenix_live_view 0.18.18) lib/phoenix_live_view/diff.ex:544: anonymous fn/4 in Phoenix.LiveView.Diff.traverse_dynamic/7
(elixir 1.14.2) lib/enum.ex:2468: Enum."-reduce/3-lists^foldl/2-0-"/3
(phoenix_live_view 0.18.18) lib/phoenix_live_view/diff.ex:396: Phoenix.LiveView.Diff.traverse/7
(phoenix_live_view 0.18.18) lib/phoenix_live_view/diff.ex:139: Phoenix.LiveView.Diff.render/3
(phoenix_live_view 0.18.18) lib/phoenix_live_view/static.ex:252: Phoenix.LiveView.Static.to_rendered_content_tag/4
(phoenix_live_view 0.18.18) lib/phoenix_live_view/static.ex:135: Phoenix.LiveView.Static.render/3
(phoenix_live_view 0.18.18) lib/phoenix_live_view/controller.ex:39: Phoenix.LiveView.Controller.live_render/3
(phoenix 1.7.2) lib/phoenix/router.ex:430: Phoenix.Router.__call__/5
(market 0.1.0) lib/market_web/endpoint.ex:9: MarketWeb.Endpoint.plug_builder_call/2
After mix.ecto.reset
, some part of the form_component works again as long as commentting out <.input …> fields in the form_component.