f0rest8

f0rest8

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.

Showing Posts 1 to 2

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.

f0rest8

f0rest8 OP

Oh wow! Great to know, thanks! I looked at that and I see that what I’m doing is this method from the stack overflow solution:

HTML 5 introduces the form attribute. This allows you to provide one form per row outside the table and then associate all the form control in a given row with one of those forms using its id.

Except I am still wrapping the row in the form, if it is the currently edited row, which now I understand to be not to spec. Thank you!

— All posts loaded —

Where Next? Top

Trending in Guides/Tuts Top

c4lliope
# ~/src/livebook/.iex.exs System.cmd("xdg-open", [ LivebookWeb.Endpoint.access_url() ] ) Because Livebook requires a unique passcode on ...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews