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 html - Form inside a table - Stack Overflow 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

pel_daniel
Hi! I created some animations to explain what happens internally with map &amp; reduce functions. The code is open source. Any feedback...
New
New
zachallaun
Hey friends, wanted to share a tiny shell script I’ve been using to start Livebook with easy access to either a running production server...
New
marcelo
I wrote a small article on how to use current_user with coherence on Phoenix. There are already a couple of blogposts about it but I thin...
New
bentanweihao
I wrote a thing: http://engineering.pivotal.io/post/how-to-set-up-an-elixir-cluster-on-amazon-ec2/ Hope this is helpful!
New
9mm
So I’m really loving elixir. BY FAR the most excruciating piece of learning a functional language for me is having to “transform” all my ...
New
GenericJam
Just leaving some breadcrumbs for future me and future others like me. Connect with TCP (not secured) - most servers will reject but use...
New
danschultzer
I wrote this blog post based on our experiences setting up continuous delivery for our first production umbrella Phoenix app. Coming from...
New
wfgilman
I'm writing up this quick "How to" because what I thought was going to be an easy implementation of a Plug to validate a webhook request ...
New
tonydang
I recently got inertia-phoenix (an Inertia.js adapter for Phoenix) working with Svelte. Setting up the server-side rendering (SSR) with S...
New

Other popular topics Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
William
I would like to know that is there any online source for learning Phoenix Framework for building E-Commerce Store? Any advantage on build...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
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

We're in Beta

About us Mission Statement