Skip to content

Commit

Permalink
Fix singular embed clearing
Browse files Browse the repository at this point in the history
tfwright committed Nov 13, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 15c3fd4 commit 2c9403d
Showing 3 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions assets/js/app.js
Original file line number Diff line number Diff line change
@@ -56,9 +56,9 @@ Hooks.EmbedComponent = {
});

this.el.addEventListener("live_admin:embed_delete", e => {
e.target.nextElementSibling.remove();
e.target.parentElement.classList.add("hidden");

const deleteInput = e.target.previousElementSibling;
const deleteInput = e.target.closest(".embed__group").querySelector("input[value=\"\"]");
deleteInput.disabled = false;
deleteInput.dispatchEvent(new Event("input", {bubbles: true, cancelable: true}));
});
6 changes: 3 additions & 3 deletions dist/js/app.js

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion lib/live_admin/components.ex
Original file line number Diff line number Diff line change
@@ -71,7 +71,6 @@ defmodule LiveAdmin.Components do
/>
<% end %>
<% else %>
<input type="hidden" name={input_name(@form, @field)} value="" disabled />
<a href="#" class="button__remove" phx-click={JS.dispatch("live_admin:embed_delete")} />
<% end %>
<div>
@@ -100,6 +99,9 @@ defmodule LiveAdmin.Components do
/>
<a href="#" phx-click={JS.dispatch("live_admin:embed_add")} class="button__add" />
<% end %>
<%= if match?({_, _, %{cardinality: :one}}, @type) do %>
<input type="hidden" name={input_name(@form, @field)} value="" disabled={!!input_value(@form, @field)} />
<% end %>
<% else %>
<pre><%= @form |> input_value(@field) |> inspect() %></pre>
<% end %>

0 comments on commit 2c9403d

Please sign in to comment.