-
-
Notifications
You must be signed in to change notification settings - Fork 84
Description
First of all, thanks a ton for this great library π
I have the following schema (abridged):
defmodule ClientApiConfig do
schema "client_api_config" do
polymorphic_embeds_one(:args,
types: [
legal_tracker: DataIngestion.LegalTracker.ApiArgs,
counsellink: DataIngestion.Counsellink.ApiArgs,
ebiller_mock: DataIngestion.Api.DummyArgs
],
on_replace: :update,
on_type_not_found: :changeset_error
)
end
endThen in my HTML form, following the LiveView example I have:
<%= for args_form <- polymorphic_embed_inputs_for(f, :args) do %>
<%= hidden_inputs_for(args_form) %>
<%= case get_polymorphic_type(f, ClientApiConfig, :args) do %>
<% :counsellink -> %>
... inputs for counsellink
<% :legal_tracker -> %>
...inputs for legal_tracker
<% end %>
<% end %>
(sidenote, I think the LiveView example is wrong, it should be get_polymorphic_type(f, Reminder, :channel) and not get_polymorphic_type(channel_form, Reminder, :channel))
The above form works if I'm editing new data which already contains an :args embed. If however I want to edit a new record and I start from an empty %ClientApiConfig{}, no fields will be rendered because polymorphic_embed_inputs_for(f, :args) returns [] (there's no :args embed and therefore no :__type__ field in it, I guess).
How can I enforce a default type? I can do that with polymorphic_embed_inputs_for/4, but since I'm using LV, I thought I'm supposed to use polymorphic_embed_inputs_for/2. Or perhaps I should use the undocumented to_form/5?
Seems to me that polymorphic_embed_inputs_for/2 should be extended to accept a type parameter.