tegmentum
Embeds_many ids not submitted in params
I’m having trouble updating a embeds_many field. My setup is the following:
<.simple_form
for={@form}
id="draft_order-form"
phx-target={@myself}
phx-change="validate"
phx-submit="save"
>
<.inputs_for :let={item} field={@form[:items]}>
<.input type="number" field={item[:quantity]} min={0} max={25}/>
</.inputs_for>
</.simple_form>
That gives me the following markup
<div phx-feedback-for="draft_order_creation_form[items][0][quantity]" class="phx-no-feedback">
<input type="number" name="draft_order_creation_form[items][0][quantity]" id="draft_order_creation_form_items_0_quantity" value="1" max="25" min="0">
</div>
My understanding is that i need the item.id to correctly update the changeset, but the params i receive from the “validate” event handler don’t include ids for items. I expect that this markup is making sure the ids make it to the params, but that is not the case
%{
"_target" => ["draft_order_creation_form", "items", "0", "quantity"],
"draft_order_creation_form" => %{
"items" => %{"0" => %{"_persistent_id" => "0", "quantity" => "2"}},
}
}
Any help would be much appreciated
First Post!
thiagomajesk
Last Post!
tegmentum
I noticed the following hidden input is being added by inputs_for
<input type="hidden" name="draft_order_creation_form[items][0][_persistent_id]" value="0">
But this is the changeset i’m turning into a form with to_form, why wouldn’t there be an id in the params ?
the form: %Phoenix.HTML.Form{
source: #Ecto.Changeset<
action: :validate,
changes: %{
items: [
#Ecto.Changeset<
action: :insert,
changes: %{
id: "01J3TDKVKQNFGMMM44FP0N8074",
name: "400g / Einzeldose",
image: "a",
quantity: 1,
price: Decimal.new("2.99"),
variant_id: "01J3TDKVKQNFGMMM44FP0N8074"
},
errors: [],
data: #Pdex.DraftOrderCreationForm.Item<>,
valid?: true
>
],
shipping: #Ecto.Changeset<
action: :insert,
changes: %{method: "dpd"},
errors: [price: {"can't be blank", [validation: :required]}],
data: #Pdex.DraftOrders.Shipping<>,
valid?: false
>,
discount: #Ecto.Changeset<
action: :insert,
changes: %{unit: :money},
errors: [value: {"can't be blank", [validation: :required]}],
data: #Pdex.DraftOrders.Discount<>,
valid?: false
>
},
errors: [
customer_id: {"can't be blank", [validation: :required]},
shipping_address_id: {"can't be blank", [validation: :required]},
billing_address_id: {"can't be blank", [validation: :required]}
],
data: #Pdex.DraftOrderCreationForm<>,
valid?: false
>,
impl: Phoenix.HTML.FormData.Ecto.Changeset,
id: "draft_order_creation_form",
name: "draft_order_creation_form",
data: %Pdex.DraftOrderCreationForm{
order_id: nil,
customer_id: nil,
shipping_address_id: nil,
billing_address_id: nil,
note: nil,
market_id: "01J3TCZA758GVB40QD7RWD6DTB",
tags: [],
discount: nil,
shipping: nil,
items: []
},
action: nil,
hidden: [],
params: %{
"customer_id" => "",
"customer_id_text_input" => "",
"discount" => %{
"_persistent_id" => "0",
"reason" => "",
"unit" => "money",
"value" => ""
},
"items" => [
%{
"id" => "01J3TDKVKQNFGMMM44FP0N8074",
"image" => "a",
"name" => "400g / Einzeldose",
"price" => "2.99",
"product_name" => nil,
"quantity" => 1,
"variant_id" => "01J3TDKVKQNFGMMM44FP0N8074"
}
],
"items_text_input" => "",
"market_id" => "01J3TCZA758GVB40QD7RWD6DTB",
"note" => "",
"shipping" => %{"_persistent_id" => "0", "method" => "dpd", "price" => ""},
"tags_empty_selection" => "",
"tags_text_input" => ""
},
errors: [
customer_id: {"can't be blank", [validation: :required]},
shipping_address_id: {"can't be blank", [validation: :required]},
billing_address_id: {"can't be blank", [validation: :required]}
],
options: [method: "post"],
index: nil
}
0
Popular in Discussions
Are there any Elixir or Erlang libraries that help with this? I’ve been thinking how streaming services like twitch have exploded recentl...
New
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition)
It’s been a while since we first asked this, I...
New
There’s a new TIOBE index report that came out that shows Elixir is still not in the top 50 used languages.
It also goes on to call Elix...
New
I’ve just started the Phoenix part of the utterly brilliant online course by @pragdave. On generating the Phoenix app he uses the --no-ec...
New
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
I have a sample string
sentence = "Hello, world ... 123 *** ^%&*())^% %%:>"
From this string, I want to only keep the integers, ...
New
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New
Other popular topics
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
What is the proper way to load a module from a file in to IEX?
In the python world, doing something like this pretty standard:
from ....
New
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible.
total = 10
while total != 0
...
New
Hi All,
I set a environment variables in dev.exs , like below code.
when i start server, how can i set the ${enable} value?
thanks.
d...
New
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
New
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
Latest Phoenix Threads
Chat & Discussions>Discussions
Latest on Elixir Forum
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
- #api
- #forms
- #metaprogramming
- #security
- #hex









