f0rest8

f0rest8

Tip for rendering forms per row in a table (e.g. the new phx 1.7 table component)

Hi,

TLDR: form attribute set on the input fields and button submit.

I just wanted to share a solution I discovered when making live inline table row editing with phx 1.7 and the latest LiveView using a slightly modified table component from the one provided in new phx 1.7 projects.

I had run into an issue where the form would suddenly become null and I found a solution by adding a form attribute to the input fields and the button for submitting the form.

That kept the forms in sync when clicking to a new row and they would be rendered or not based on a helper function that would determine if and which row is being edited.

I don’t think I’m allowed to share the code since it is for my non-Metamorphic job. But if anyone is struggling with this kind of situation, and has gotten as far as having the form able to submit at least once on a full page refresh, then this may be the answer.

And I debugged it by setting a hook on the button and checking out whether the form was being populated or set to null whenever an event would go over the wire with

Hooks.Submit = {
  mounted() {
    console.log("Hook mounted!", this.el);
  },
  updated() {
    console.log("Hook updated!", this.el);
  }
}

Anyway hope this helps, sorry it’s not a clearer code showcase. Update: you don’t necessarily need to add the formaction attribute.

Most Liked

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Hey @f0rest8 per this stack overflow https://stackoverflow.com/questions/5967564/form-inside-a-table the HTML spec does not allow <form> tags to be a child of a table. There are some workarounds but they’re not the most ergonomic. I would suggest not using an actual <table> and instead use a list that is styled to look like a table.

Where Next?

Popular in Guides/Tuts Top

dennisreimann
I wrote a guide for implementing Passwordless Authentication a.k.a. “Magic Login Links”: https://dennisreimann.de/articles/phoenix-passw...
New
ben-pr-p
https://github.com/ben-pr-p/elixir-phoenix-parcel-example Hey all! I put together a starter-pack / instructions to set up Phoenix with t...
New
hlx
Typed my very first blog post ever, hope it will help some people https://henricus.xyz/roll-your-own-email-password-authentication-with-...
New
sergio
https://sergiotapia.me/generate-images-with-name-initials-using-elixir-and-imagemagick-374eca4d14ff Hope this saves you guys some time!...
New
yeshan333
vfox (version-fox) is a popular general version management tool write in Go, and the plug-in mechanism uses Lua to achieve extensibility....
New
Eiji
Hey, today I give amnesia library a try and found a few problems. I would like describe how to setup it properly and solve problems which...
New
kokolegorille
Hello dear alchemists, There was this question some days ago here about the deployment to a VPS. As I was in the process of deploying t...
New
niku
I have published an elixir project with using Travis CI. I would like to share some tips &amp; thoughts that I was getting through this ...
New
eclark
I’ve been working on a phoenix project lately and I wanted to use the latest versions of everything. Webpack 5 had some breaking changes ...
New
anuragg
We just published a guide to automatic clustering in Elixir 1.9, with Mix releases and libcluster. The cluster automatically discovers n...
New

Other popular topics Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
AstonJ
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31142 143
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New

We're in Beta

About us Mission Statement