James_E

James_E

Suppressing updates to an Input field while it's selected?

I’ve got a Phoenix LiveView that is updating part of its state every second.

I need to allow certain users to update a different part of the state at any point. I built this widget to do so:

<div class="tw-text-3xl tw-font-bold tw-relative tw-group">
  <.countdown_widget
    label="T‒0"
    duration={Timex.diff(@state._meta.now, @state.t0, :duration)}
  />
  <%= if {@is_director} do %>
    <div class="tw-absolute tw-top-[100%] tw-inset-x-0 tw-hidden group-hover:tw-block group-focus:tw-block tw-z-10" role="none">
      <form action="javascript:"><input
        type="datetime-local"
        name="t0"
        title="T‒0"
        value={Timex.format!(@state.t0, "%Y-%m-%dT%H:%M:%S", Timex.Format.DateTime.Formatters.Strftime)}
        phx-change={JS.push("set_t0")}
        step="1"
      /></form>
    </div>
  <% end %>
</div>

however, this doesn’t seem to work. On Chrome and Edge (which will be the only options in prod), the input field is reset to be empty every time @state._meta.now ticks.

Is there any way to freeze the input so it can’t be updated by the server while it’s selected by the user?

Most Liked

James_E

James_E

My bad. This while-focused update suppression is enabled by default, but works in Edge and Chrome only when the initial value field applied to the datetime input is valid. The formatting function I was originally using didn’t output correct results; fixing that made it start working.

I don’t understand this, I have no idea why that would break this, but Phoenix was apparently doing the right thing by default here.

Where Next?

Popular in Questions Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
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
Lily
In templates/appointment/index.html.eex: &lt;%= for appointment &lt;- @appointments do %&gt; &lt;tr&gt; &lt;td&gt;&lt;%= appoi...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
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
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

Other popular topics Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
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
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
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
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