-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Working with embeds_many #3
Comments
Hi!
Yes, you should be able to use it with embedded schemas. For this case you could mark the changeset action as
schema "items" do
...
field :delete, :boolean, virtual: true
field :new, :boolean, virtual: true
end
defp maybe_mark_for_deletion_or_ignore(changeset) do
delete? = get_change(changeset, :delete)
new? = get_change(changeset, :new)
if delete? do
%{changeset | action: if(new?, do: :ignore, else: :delete)}
else
changeset
end
end
end
<%= dynamic_inputs_for f, :items, %Item{new: true}, [only_mark_deleted: true], fn item -> %>
<%= hidden_input item, :new %>
<%= text_input item, :title %>
<%= text_input item, :content %>
<%= dynamic_delete_button "Remove" %>
<%= error_tag answer, :content %>
<% end %>
<%= dynamic_add_button :items, "Add" %> Please note that I use the only_mark_deleted option for the form. So only the class There may be something wrong with the code because I haven't checked it, but I hope it will serve as an example for you. |
Thanks a lot for this library! It's awesome =)
|
Hello!
Is it possible to use your library with an
embeds_many
? I'm trying to use it in a LiveViewlive_modal
, with deletions enabled by the virtual field method described in the README. This is what I have in theform_component.html.leex
template:If I add an item, save the form, then remove the item, everything works fine. However, if I add an item, remove it and only then try to save the form, I get this error:
I suppose the fix would be to actually delete the field if it wasn't already saved, I just don't know how to do it.
Thanks a lot for creating this library!
The text was updated successfully, but these errors were encountered: