bvobart
Hi Elixir forum!
I have a function component to view, edit and delete an object from my database. This component obviously contains a form to perform and submit the edits that the user makes, but it also contains a Delete button to delete it, see the screenshot below.
Shortened for brevity, this is the implementation of that component:
<div class="...">
<.form for={@form} phx-change="validate-changes" phx-submit="save-changes">
<%!-- form inputs here --%>
<footer class="flex justify-between items-center">
<div class="flex gap-2">
<.button
variant="secondary"
disabled={not changed?(@form)}
phx-disable-with="..."
>
Save
</.button>
<.button {[{@return_method, @return_to}]}>Cancel</.button>
</div>
<.button
variant="outline"
class="btn-md btn-error text-error hover:text-base-100"
phx-click="delete"
phx-value-id={@job_request.id}
data-confirm="Are you sure you want to delete this job request?"
>
<.icon name="hero-trash" class="size-5" />
</.button>
</footer>
</.form>
</div>
My problem is that whenever I click the Delete button, it not only triggers the delete event like I want it to, but it also triggers the form submission, thus causing the save-changes event to be fired as well. How do I prevent that from happening so that only the delete event gets fired?
What I’ve tried so far:
- Use
phx-clickwith“delete”. Does not work, as described. - Use
phx-clickwithJS.push(“delete”) |> JS.patch(@return_to). Does not work, same problem. - Tried putting the same props as what the Cancel button gets on the Delete button (effectively:
patch={@return_to}), along withphx-click="delete". Does not work, thedeleteevent is never triggered, only the patch is executed. - Moved the Delete button outside of the
.formcomponent, but then I couldn’t figure out how to neatly style the button to still be positioned in the same way the screenshot shows. - I read in the docs that
phx-changecan also be applied on individual elements rather than just the form, which would cause the form’s change event to be ignored and only the individual element’s change event to be fired. I thought maybe the same applies tophx-submit, but it does not: puttingphx-submit=”delete”or something similar on the Delete button has no effect and the problem still persists.
Do you have any ideas for a good solution?
important to note:
- the
.buttoncomponent was generated by Phoenix 1.8.1 when I created the project, I merely extended the variants and made it possible to extend the classes passed down into it.- the Cancel button works just fine and doesn’t trigger a form re-submission, because the generated
.buttoncomponent renders as a.linkwhen given an href, navigate or patch prop.
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
I’m aware of 2 such projects, are there others?
git: GitHub - team-alembic/realworld: A fullstack Phoenix LiveView application with back...
New
Hi all,
I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
Hi everyone.
My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
Hi,
we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New
Hi all, I’m new here and would like to hear peoples views on my Elixir/Phoenix based game-engine! :smiley:
Mutonex gamedesign was finish...
New
Do we have maintainer of absinthe-graphql/dataloader here? We have a PR that we’d like to merge to the library. Relatively small additive...
New
Other Trending Topics
Hey there,
I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first.
...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly)
AI dream has many faces, but general...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #blog-post
- #ecto-query
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #hex











Showing Posts 4 to 1- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
garrison
Apparently someone just popped by and added it one day, probably unaware that it was “supposed” to be a list of global attributes! TBH I don’t think the idea of the list being global-only is helpful anyway, there are a number of common attributes that I hate having to put in
:includeevery time.garrison
Huh, you’re right. The docs explicitly state that the list of HTML global attributes is used but type is in there despite not being a global attribute.
That line in the docs should probably be updated!
bvobart
Thanks,
AI already gave me this answer but because
type=buttoncombined withphx-click={JS.push(“delete”) |> JS.patch(@return_to)}solves it! Now I feel stupid for not trying that earliertypeisn’t in theincludelist forattr :reston the default generated button component, I thought it was just a bogus response.For those who were just like me looking for an explanation as to why this works and is valid, see the MDN docs: <button> HTML button element - HTML | MDN
garrison