Hello all!
I am having some trouble generating a custom form for dynamic gps coordinate input fields.
I have created a custom input helper:
def create_li(form, field, input_opts \\ [], data \\ []) do
type = Phoenix.HTML.Form.input_type(form, field)
#name = Phoenix.HTML.Form.input_name(form, field) <> "[]"
lat = Phoenix.HTML.Form.input_name(form, field) <> "[][point][lat]"
lat_opts = Keyword.put_new(input_opts, :name, lat)
long = Phoenix.HTML.Form.input_name(form, field) <> "[][point][long]"
long_opts = Keyword.put_new(input_opts, :name, long)
content_tag :li do
[
apply(Phoenix.HTML.Form, type, [form, field, lat_opts]),
apply(Phoenix.HTML.Form, type, [form, field, long_opts]),
link("Remove", to: "#", data: data, title: "Remove", class: "remove-array-item")
]
end
end
Which posts this:
%{
"content" => "",
"description" => "",
"geom" => [
%{"point" => %{"lat" => "1"}},
%{"point" => %{"long" => "2"}},
%{"point" => %{"lat" => "3"}},
%{"point" => %{"long" => "4"}}
],
"h3id" => "",
"title" => "test",
"type" => "test"
}
But I would like it to be:
%{
"content" => "",
"description" => "",
"geom" => [
%{"point" => %{"lat" =>"1", "long" => "2"}},
%{"point" => %{"lat" => "3", "long" => "4"}},
],
"h3id" => "",
"title" => "test",
"type" => "test"
}
Thank you in advance for any help!
Kind regards!