vicb335

vicb335

Form doesn't always get cleared after submitting

When submitting the form, the inputs should clear once I pass an empty changeset, they dont seem to be doing that if I am successful on the first try.
Heres what I mean

  1. the first time the form was correct, it doesnt get cleaned (unexpected)
  2. then I failed with bad inputs, it doesnt get cleaned (expected)
  3. then I submit a correct version, it does get cleaned (expected)

Marked As Solved

sodapopcan

sodapopcan

You mean phx-change? phx-update is not an event, it’s an instruction on how to handle DOM patching. But yes, you must handle phx-change to keep track of your form’s state server-side. You could implement some JS to do it client-side, but this would defeat the purpose of LiveView.

Also Liked

rhcarvalho

rhcarvalho

Perfect way to describe it, thanks!

While testing a new feature we ran into this situation which, at the time, we could not explain. Why was the form not updating?! :confused:

It turned out that the particular form input also had phx-debounce, to avoid flooding the server with phx-change events, and if no such events were sent before submit, then the form state from the server’s perspective never changed, and the form input was not re-rendered and cleared!

Your account of the problem was key to realizing what was going on :purple_heart:

garrison

garrison

What is actually going on here is that LiveView’s declarative abstraction is fundamentally leaking its imperative implementation. This is the sort of bug that is not supposed to happen with a declarative programming model.

In e.g. React this is fixed with controlled inputs which always have their state forcibly reset in lock-step with the render (this is declarative programming). Unfortunately this is one of very few things that I think genuinely cannot be fixed in LiveView because it is a consequence of server latency. In almost every case server latency is not a problem, but here it actually is.

This also means that @bartblast should take note, as if he implements controlled inputs correctly this is a case where Hologram will just be strictly and unavoidably better.

LostKobrakai

LostKobrakai

Concurrent changes to a shared input value between the client and the server under latency are not trivially handled. You run into all the problems of distributed computing there. Even client side libraries in the past got this stuff wrong - and they didn‘t have a network on the path. LV does.

Where Next?

Popular in Questions Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

Other popular topics Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36820 110
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
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New

We're in Beta

About us Mission Statement