polymorphic_embed icon indicating copy to clipboard operation
polymorphic_embed copied to clipboard

PolymorphicEmbed.HTML.Form.get_polymorphic_type doesn't respect `type_field` option

Open omginbd opened this issue 3 years ago • 4 comments

Observed behavior

When creating a form to edit a schema with a polymorphic embed using a custom type_field, PolymorphicEmbed.HTML.Form.get_polymorphic_type returns nil regardless of the data shape.

I believe this is due to the hardcoded match for "__type__"/:__type__ keys when matching on the result of input_value(form, field).

This seems to be confirmed by adding a <%= hidden_input(f, :__type__, value: input_value(f, :actual_type_field) %> to the form, which seems to make it work.

Expected behavior

PolymorphicEmbed.HTML.Form.get_polymorphic_type should match on thetype_field value set in the schema.

Thanks for the work on this great library!

omginbd avatar Sep 22 '22 21:09 omginbd

I'll try to fix that shortly. Note that if you add a failing test case, I'll resolve it the same day. Otherwise no problem I'll just need a a little more time cause I'm in a tight sprint currently at my job 😂

mathieuprog avatar Sep 23 '22 03:09 mathieuprog

Could you test the error you get from v3.0.5 ?

mathieuprog avatar Sep 30 '22 06:09 mathieuprog

Can I see your code? Ie how you call Form.get_polymorphic_type ? Because this piece of code has been added by a contributor, I am not using it personally, and it'd be faster if you explain me your case and what is passed as arguments.

mathieuprog avatar Sep 30 '22 06:09 mathieuprog

ping @omginbd

mathieuprog avatar Oct 02 '22 10:10 mathieuprog