polymorphic_embed icon indicating copy to clipboard operation
polymorphic_embed copied to clipboard

Fix param handling

Open nduitz opened this issue 4 months ago • 3 comments

This fixes two things:

a) It picks up the correct action (not from the changeset but from the parent form) b) It fixes handling parameters for cardinality :many

If you remove the first commit you will see the test is failing and it will produce the incorrect form. Instead of generating two forms per polymorphic type it will generate only one form for the device type

nduitz avatar Aug 16 '25 08:08 nduitz

This PR seems to fix some of the immediate form validation problems I was having (even though the issue you were mentioning this PR in (#113) is about polymorphic_embeds_many, and I was having trouble with polymorphic_embeds_one).

There seems to be one failing test though

  1) test form with improved param handling for different param types (PolymorphicEmbedTest)
     test/polymorphic_embed_test.exs:3234
     Assertion with == failed
     code:  assert f.params == %{"ref" => "789"}
     left:  %{"0" => %{"ref" => "789"}, "1" => %{"address" => "012 Oak Ave"}}
     right: %{"ref" => "789"}

I am not sure why this is happening though, as right now I didn't dive deep enough into phoenix form handling yet. Maybe it is happening because recent changes in phoenix html/form handling?

Furthermore, you mentioned in #113 that there were issues with the sort params as well, specifically with the approach taken in this PR.

Did you find some time to have another look at this yet @nduitz ?

rmoorman avatar Oct 10 '25 14:10 rmoorman

Hey there, we are currently running this branch in our project which works well so far: https://github.com/nduitz/polymorphic_embed/commits/patch-2

One thing I noticed yesterday which caused me a lot of headaches was that polymorphic_embed_inputs_for does not render hidden id inputs even though we do not specify skip_hidden: true. Will look into that once we finished implementing all forms and continue to refine them.

nduitz avatar Oct 23 '25 16:10 nduitz

Hey there, we are currently running this branch in our project which works well so far: https://github.com/nduitz/polymorphic_embed/commits/patch-2

One thing I noticed yesterday which caused me a lot of headaches was that polymorphic_embed_inputs_for does not render hidden id inputs even though we do not specify skip_hidden: true. Will look into that once we finished implementing all forms and continue to refine them.

Never mind my comment about polymorphic_embed_inputs_for not rendering a hidden id field. That is the same for the inputs_for implementation of phoenix_live_view. Somehow I assumed inputs_for does this.

nduitz avatar Oct 23 '25 16:10 nduitz