augnustin
Hello,
I’d like my button("content", to: url) to have extra hidden fields in it, like button("content", to: url, params: %{field: "value"}) is this possible?
The same question went in Rails: https://stackoverflow.com/questions/4886963/how-to-add-additional-params-to-a-button-to-form and it is now possible. ![]()
Cheers
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
Hello
I’ve been coding in Elixir for almost two years now because of my current job where we implemented Elixir in our application. But ...
New
Other Trending Topics
Hey Elixir folks,
I’ve been working on Xenia 0.2.0, and it’s nearly ready.
This release focuses on performance, easier integration, and...
New
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
(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
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
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 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
albydarned
From the docs
Try
Image from my test:

augnustin
Apologies if I have been unclear but I’d like
custom=propertyto be sent out within the ajax call that submits the form, while your solution only adds an html custom attribute, doesn’t it?albydarned
I see, so this button is in a form?
Have you considered adding properties as hidden inputs?
LostKobrakai
I’m not sure why this was added to rails, but conceptionally it seems quite strange to exist. GET parameters are part of the url, so I’m not sure why they should be added via options on the button. Phoenixs’ route helpers allow you to add GET parameters to urls as well as the
URImodule of the elixir core. If you’re looking for additional body params you’d need to wrap the button in a form to submit, which has some hidden inputs.OvermindDL1
Phoenix doesn’t use javascript to perform ajax calls, Phoenix is just a server that lets you do on the front-end whatever you wish. If you have something that needs to perform ajax calls then it is that which should do it, phoenix will just handle the back-end side. What front-end are you using that performs ajax in the browser?
augnustin
Completely agreed with the fact that
GETparameters should be in the query URL.But
button\2is actually more useful in the case of aPOST/PUT/DELETEquery IMHO, whereparamsact as extra hidden fields.Anyway, since it is phoenix_html.js which actually submits data, it could be conditional on the
methodso thatGETis in the query parameter, and others are hidden fields.I guess that’s what Rails does.
Cool thing about this is that
methodcan be dynamic without having to rewrite the logic:augnustin
Oh ok, I thought it would, like
rails_ujsdoes. But apparently it does has JS dependency.Of course, one can do without it, but in this case, it seems pretty reasonable to use it the phoenix-way so that front-end and back-end plug each other easily.
Rails is really great at doing this, and I guess if phoenix is so much inspired from it, it means it is trying to reach the same convenience.
augnustin
Basically instead of
I’d expect to go for:
And this would work for either
:getand:post.LostKobrakai
Phoenix’s button handling with
methodis mostly a convenience to not need to wrap just a button with a form, to defines nothing more than a url/method. If you need more data as part of the request use a form with hidden fields. You’re imho past the point there the convenience does make much sense.For get requests you could alter the url, but a form will also just use get params if you submit it with the
GETmethod. I guess both ways are viable for get parameters.If you’d use
form_forinstead ofcontent_tag(:form, …)you’d get the csrf token and the method override automatically and it would therefore work for any http method.OvermindDL1
No clue what
rails_ujsis, but I can’t imagine such a feature working without javascript support for it, and thus it will fail when javascript is disabled. It’s really not something that should be relied on.