nested form issue
Hi Guys!
I am trying to apply a simple nested form, and I can not get through.
The use-case is simple: I want to add supplier_prices to my users. I tried to do everything according to the docs, probably missed something.
user.ex:
follow up in comment(s)(?).
29 Replies
user_live/form_component.ex:
- the error upon submit:
- Form Error: [
%Ash.Error.Changes.InvalidArgument{
field: :supplier_prices,
message: "is invalid",
value: %{
"_form_type" => "create",
"_persistent_id" => "0",
"_touched" => "_form_type,_persistent_id,_touched,_unused_currency_id,_unused_source_language_id,_unused_target_language_id,_unused_task_config_id,_unused_unit_type_id,currency_id,price,source_language_id,supplier_id,target_language_id,task_config_id,unit_type_id",
"currency_id" => "1",
"price" => "32434",
"source_language_id" => "1",
"supplier_id" => "2",
"target_language_id" => "1",
"task_config_id" => "1",
"unit_type_id" => "1"
},
splode: nil,
bread_crumbs: [],
vars: [index: 0],
path: [0],
stacktrace: #splode.Stacktrace<>,
class: :invalid
}
]
my guess is, that the user.ex awaits a list of maps instead of a simple map, which is provided (and with correct values) I can not get through this issue.
field: :supplier_prices,
message: "is invalid",
value: %{
"_form_type" => "create",
"_persistent_id" => "0",
"_touched" => "_form_type,_persistent_id,_touched,_unused_currency_id,_unused_source_language_id,_unused_target_language_id,_unused_task_config_id,_unused_unit_type_id,currency_id,price,source_language_id,supplier_id,target_language_id,task_config_id,unit_type_id",
"currency_id" => "1",
"price" => "32434",
"source_language_id" => "1",
"supplier_id" => "2",
"target_language_id" => "1",
"task_config_id" => "1",
"unit_type_id" => "1"
},
splode: nil,
bread_crumbs: [],
vars: [index: 0],
path: [0],
stacktrace: #splode.Stacktrace<>,
class: :invalid
}
]
my guess is, that the user.ex awaits a list of maps instead of a simple map, which is provided (and with correct values) I can not get through this issue.
What exactly should it do when you add a new form to the list?
Your current manage relationship is using
type: :append_and_remove
Which is for relating to existing things on the other endlove you man, I thought you were out for the weekend 😄
Can I see where you are creating the form?
so I don't really know, this is kind of a black box for me, I thought append_and_remove can edit or add or remove kind of automatically the prices
I also added the render function's <.input_for ... if that is what you mean
No like
AshPhoenix.Form.for_create
that looks like it should be a direct_control
Agreed. The invalid argument is weird though.
I don't really get what you mean, where do I have to add this?
I'll try this
I'm saying that somewhere in your code already
Like on mount
You are making the form
I need to see that code
Okay, so that's the issue
@impl true
def update(assigns, socket) do
{:ok,
socket
|> assign(assigns)
|> assign_form()
|> assign_select_options()
}
end
1. api hasn't been an option in Ash for like 2 years 😂
2. You don't need to specify the forms option, it is derived from the action automatically
yeah, kinda relying too much on ai...
If you had wanted to do it with manual config, you'd need
type: :list
🙂so if i simply do this:
Please try to let us know to what degree AI has generated code you're asking for help with, as a human likely never would have arrived at that code naturally. I don't mind helping with AI generated code provided you've tried to figure out the answer yourself
But it does also make us basically "other people's AI debuggers"
😂
yeah, no, I first tried to go with the documentations
not just plain AI
but it didn't work at first, and tried to patch, and patch, and patch
I couldn't figure that direct_control, or append_and_remove could have been an issue
All good, manage relationship and nested forms are one of the more complex parts of ash
now I have a validation issue:
I believe, the function:
is not good now
as the pattern changed
to something like: %{"_target" => ["form", "name"], "form" =>
You removed
as: "user"
from your opts I assume
Add that back inyeah, that helped, thanks.
now i could save one price for a user, and it is preloaded with the form on edit, now without modifying anything, upon trying to save the form, I get:
Something very strange there 😅
Not seen that error before. Hard to say what the issue might be. It's certainly not normal. What are the params you're submitting?
what's on
lib/orca_link/orca_link_ash/business_logic/versioning/historization.ex:47
?Oh, is it related to that? It's my custom code, but I'll switch it off and try saving without it, and if it is causing the error I'll handle it.
Tl;dr, I have a generic versioning implementation.
its the second line of the error stack trace, so I think so
yeah, thanks, this is not a framework issue!