polymorphic_embed
polymorphic_embed copied to clipboard
PolymorphicEmbed.HTML.Form.get_polymorphic_type doesn't respect `type_field` option
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!
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 😂
Could you test the error you get from v3.0.5 ?
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.
ping @omginbd