TwistingTwists
Custom `input_type` for Custom Structs
I need to create a form for custom defined struct which has another nested struct (to be represented as formarray)
%MyOuterStruct{ key: :value,
inner_key:
%{16=> %InnerStruct{key2: :value2},
17=> %InnerStruct{key2: :value3}
}
I have defined changesets for both of these structs in their respective files.
Issue I am facing:
no function clause matching in Phoenix.HTML.Form.input_type/3
Called with 3 arguments
%{16 => %InnerStruct{key2: value}}
:inner
%{"email" => :email_input, "password" => :password_input, "search" => :search_input, "url" => :url_input}
basically in a liveview form:
...
<%= create_inner f.data.outer.inner ,:inner %>
...
and input_helpers.ex contain
def create_inner(form, field, input_opts \\ [], data \\ []) do
type = HTML.Form.input_type(form, field) |> IO.inspect(label: "type of input")
.... more code ...
end
How do I create a custom input helper for my nested struct?
First Post!
al2o3cr
Usually you’d use inputs_for in this situation; I’m not sure if that’s a good fit depending on what the keys inside of inner_key (16 and 17 in the example) mean.
What shape of parameters is your event handling / changeset code expecting for MyOuterStruct?
Last Post!
TwistingTwists
16 and 17 are integer keys.
changeset code for outerstruct :
%MyOuterStruct{ key: :value,
inner_key:
%{16=> %InnerStruct{key2: :value2},
17=> %InnerStruct{key2: :value3}
}
we have typed structs and not using ecto schemas.
So, changesets for OuterStruct is written in a way that it invokes changeset for nested structs.
Popular in Questions
Other popular topics
Latest Phoenix Threads
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #hex
- #security










