chrisdel101
In LiveView how can I pass my data back to the controller? Non-liveview like Route.path_helper(conn, :new, user: @user, employee: @employee). I need the same map or keyword list as shown.
This is my latest iteration. I need those user and employee fields attached to each form, so I can’t just use html. Where can I put such a list of values here?
<.form let={_f} for={:alert} phx-submit={:alert} #user: @user, employee: @employee>
<%= submit "Alert1", class: "btn btn-primary" %>
</.form>
Then in the controller. I need value to be a map (or whatever)
def handle_event("alert", value, socket) do
IO.inspect(value) => {} # is currently an empty map. Only the first arg is correct.
I’ve asked on this question use form_for in liveview component without model or changeset. And this is similar to this too live_component inside of a form_for
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
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
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
Hello folks!
So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
I’m working on a small exercise involving update_in/3, and I came up with this solution:
data = %{
name: "Periodic Table",
category:...
New
How Can I Optimise Compile Time Dependencies
I have been building an elixir application for about 2 years now. Many modules and files ha...
New
Other Trending Topics
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
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 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
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with.
But I don’t use it anymore.
Serverless was the promis...
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
- #umbrella
- #ai
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #metaprogramming











Showing Posts 1 to 6- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
LostKobrakai
You can put the additional values in a hidden input on the form for them to be submitted with the rest of the forms data.
chrisdel101
Is that the orthodox way to do it?
Can U give an example? I can’t get it to work.
Give the error
no function clause matching in Phoenix.HTML.Form.generic_input/4codeanpeace
I’d suggest generating the hidden input via a
Phoenix.Componentrather than viaPhoenix.HTML.Formassuming you’re running a recent version of LiveView.Something like the above assuming you’ve set up the Phoenix.Component.form/1 properly.
Also, sending these ids via the form may be unnecessary if that information is already stored in your LiveView socket which is accessible in your event handlers e.g.
def handle_event("alert", value, socket), do: ... end.imkleats
Unless your use-case is more complex than the example with other non-hidden inputs, it sounds like you might be better off using a
phx-clickbinding instead of a form.chrisdel101
Thanks everyone for the ideas!
Main problem solved:
I was missing alot of knowledge. Now I see the problem was the
fielddidn’t work as I thought, i.e. automatically. I ended up just going with html after all, since yes, the rest of the details are still on the socket.Secondary problem: Re: the input component:
I didn’t know I needed to implement
<.input/>myself. I’ve tried using the example here but I getundefined function attr/2. Phoenix 1.6 I think.So I’m trying this, but I don’t know where it goes. In it’s own file? How do I use it? Since there is no render.
codeanpeace
These two are connected! On more recent versions of Phoenix, a
core_components.exfile that implements<.input/>gets generated when creating a new app viamix phx.new my_app. That implementation uses pattern matching to automatically derive and add a:nameand:valueassign based on the:fieldassign. So if you want to use<.input/>, you’ll either need to manually add this file/function or implement it yourself.https://github.com/phoenixframework/phoenix/blob/6095fb3aac9b37baa043374a0766680ab5d93a04/installer/templates/phx_web/components/core_components.ex#L277-L284
It can be a bit confusing at first, especially since the LiveView library includes a standard default
.formcomponent, but doesn’t include a standard default.inputcomponent. That’s why the autogeneratedcore_components.exfile includes a.simple_formcomponent that wraps the standard.formcomponent as well as an.inputcomponent.