TwistingTwists

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

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

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.

Where Next?

Popular in Questions Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

Other popular topics Top

axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 49084 226
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40042 209
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New

We're in Beta

About us Mission Statement