How to create a delete button for Phoenix HTML form has_many relation?

How to delete an association from a (has_many) relation

I want to delete a single association from a preloaded :has_many association, using the phoenix HTML form,

when I try to remove the input fields from the HTML form, the associated data does not get deleted but stay as they are,

how can I remove them? or in other words how to create a (delete) button?

Nested model forms with Phoenix LiveView - Tutorials and screencasts for Elixir, Phoenix and LiveView - this is one of a series of articles that probably answers a few of your questions about Ecto associations.

I found the solution for the question,
your response is about something else though I asked a qeustion about dynamic field inputs but I am not using live view

Always a good idea to post it to help future forum readers.

To create a delete button you can mark it for deletion like in docs and if the (id) field is present it gets deleted

defmodule Comment do
  use Ecto.Schema
  import Ecto.Changeset

  schema "comments" do
    field :body, :string
    field :delete, :boolean, virtual: true

  def changeset(comment, params) do
    cast(comment, params, [:body, :delete])
    |> maybe_mark_for_deletion

  defp maybe_mark_for_deletion(changeset) do
    if get_change(changeset, :delete) do
      %{changeset | action: :delete}