Havardpede

Havardpede

Updating dom on phx-change on text input

I am working on creating a multi-page application form.
I have decided to hide the next-button until there is an answer for each question on the page.
To detect when an answer is updated, I have tried the following:

  • Attaching a phx-blur to the inputs. This worked, but forced the user to exit the input, which wasnt intuitive enough in certain cases.

  • Attaching a phx-keyup to inputs. I could not find a way to attach a reference to indicate which input was being edited, so I could update the relevant answer.

  • Wrapping the inputs in a <form> with phx-change. This triggered the event correctly, but did not reload the DOM. I even converted the navbar into a live_component, and tried triggering a forced re-render with send_update/2.

Do you have any ideas on how to handle this case?

Thanks in advance :slight_smile:

Marked As Solved

outlog

outlog

ok, did the debugging..

error is the “%” at the end of your:
<input type=“string” name=“input” value=“<%= @answer %>” class=“border” %>

that breaks phoenix_live_view.js - remove that and you are good to go..

btw type=“string” is not standard HTML input type Attribute so maybe use “text”

Also Liked

outlog

outlog

socket
|> assign(:show_button, answer != "")
|> assign(:answer, answer)

{:noreply, socket}

seems like those assigns doesn’t go on the socket/reply eg you need

socket = socket
|> assign(:show_button, answer != "")
|> assign(:answer, answer)

{:noreply, socket}

this is a bit of OOP vs FP..

socket
|> assign(:show_button, answer != "")
|> assign(:answer, answer)

is basically a noop in FP - while in OOP it would most likely have mutated “socket”

Havardpede

Havardpede

Oh wow yeah that was obvious. Thank you :blush:

Havardpede

Havardpede

Thank you, @outlog that fixed it :slight_smile:

Where Next?

Popular in Questions Top

Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
earth10
Hi, I’m just starting to build a side-project with Elixir and Phoenix and doing some basic test with Elixir alone. What strikes me is th...
New
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
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
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
dotdotdotPaul
Okay, I’m having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I’m sure I’...
New
hariharasudhan94
Lets say i have map like this fetching from my database %{"_id" =&gt; #BSON.ObjectId&lt;58eb1a7a9ad169198c3dXXXX&gt;, "email" =&gt; "XXX...
New

Other popular topics Top

Nvim
Anybody knows a comprehensive comparison of Django and Phoenix, thanks for the help. Where are they similar? Where do they differ the m...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
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
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
hariharasudhan94
Lets say i have map like this fetching from my database %{"_id" =&gt; #BSON.ObjectId&lt;58eb1a7a9ad169198c3dXXXX&gt;, "email" =&gt; "XXX...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement