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?
I’d suggest generating the hidden input via a Phoenix.Component rather than via Phoenix.HTML.Form assuming you’re running a recent version of LiveView.
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.
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-click binding instead of a form.
I was missing alot of knowledge. Now I see the problem was the field didn’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.
These two are connected! On more recent versions of Phoenix, a core_components.ex file that implements <.input/> gets generated when creating a new app via mix phx.new my_app. That implementation uses pattern matching to automatically derive and add a :name and :value assign based on the :field assign. So if you want to use <.input/>, you’ll either need to manually add this file/function or implement it yourself.
It can be a bit confusing at first, especially since the LiveView library includes a standard default .form component, but doesn’t include a standard default .input component. That’s why the autogenerated core_components.ex file includes a .simple_form component that wraps the standard .form component as well as an .input component.