cantiero
I am creating a table, where users may edit some fields just by typing and changing their text. It is a functional component that my be placed in a Live Component or in a Live View. My idea is to not use forms for it, just having the input tag send the changes to the server using phx-change and dealing with it from there.
The component that renders a cell looks like this:
<td>
<input
type="text"
id={"#{@field_name}--#{@row_id}"}
name={"table[#{@field_name}--#{@row_id}]"}
value={@value}
phx-debounce={500}
phx-change={assigns[:"phx-change"]}
{Map.take(assigns, [:"phx-target"])}
/>
</td>
But, when I try to use this in a LiveView without passing a phx-target, as I want the event to be sent to the live view, the error Uncaught TypeError: Cannot read properties of null (reading 'getAttribute')... is raised by view.js at the line let cidOrSelector = target.getAttribute(this.binding("target")) in the targetComponentID method.
Not sure if this has some relation to this input not having form ancestor, or if I am missing something. Any help would be greatly appreciated.
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixir-ls
- #ai
- #elixirconf-us
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 7- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
LostKobrakai
Any reason for that? You can easily assign inputs to a form elsewhere in the page with the
formattribute, so no need to wrap the whole table in a form.cantiero
I just try to keep my markup and components as clean as possible. The
tablemay be used in a view with no editable fields and I did not want to add aformelement as its parent when it is not needed. The solution to accomplish that was looking ugly IMO.But the
formattribute solves that in an acceptable way for me. I simply did not remember it even existed.I would prefer not having to include this
formelement as it makes the functionality depend on two separate components sharing theidinformation to make an event in one of them work. Theformtag, in theory, should not need to exist. But that is just me being extremely picky.Thank you for you help!
LostKobrakai
Why would the table be aware of it’s contents in the first place? I’d imagine it like this:
No need to share any implementation details across components.
cantiero
My
tdsubcomponent was made only to be used by thetablecomponent. For now I only need one table per view. So, it all looks like this:tablecomponent is used as:table.html.heexrenders:When attribute
editor=:textbox,td.exrenders:I agree with you: I could instead add a
formattribute totd. But the ideal world for me would be not having to add theformtag intable, nor theformattribute intd, nor theformattribute in theinput. Reducing boilerplate, having a cleaner code.mxgrn
Formless inputs are not allowed in LiveView: Prevent exception with inputs without a form by mveytsman · Pull Request #2343 · phoenixframework/phoenix_live_view · GitHub
nicklayb
For anyone coming across this thread with a usecase where you wanna use a form input without form, it’s achievable with a hook pretty simply, here’s what I came up with
The Javascript hook (named Formless)
The usage
And when the select gets updated it fire the
selectUpdatedwith%{"value" => the_value}.briancbarrow
Thank you for this! I thought I was losing my mind. Good to know it isn’t supported.