neurodynamic

neurodynamic

How do I stop default generated new/edit modals in Phoenix 1.7 from scrolling me to the top of the page when closed?

I tried this with a brand new generated Phoenix 1.7 app to make sure it wasn’t something I did. If I make a new app and then use phx.gen.live to make a list of tasks, for example, when I finish editing or creating a task and the form modal closes, the browser always ends up scrolling to the very top of the page, instead of staying in the part of the list of tasks where I was before I opened the form modal.

Anyone know why this is or how to prevent it?

Marked As Solved

awerment

awerment

Seems the on_cancel={JS.navigate(~p"/<url>")} attribute in the resources’ generated index.html.heex is the culprit. It triggers a re-mount of the parent LiveView, hence the scroll position is lost.

For me, it’s fixed with on_cancel={JS.patch(~p"/<url>")}.

Update: should note that I wasn’t able to reproduce the behaviour when actually saving an entry (clicking “Save” button or pressing return), it only occurred for me when canceling out of the modal (clicking away or the “x” cancel button, pressing escape). I did notice that sometimes the scroll position was already reset as soon as the modal opened, but could not track that down.

Also Liked

wceolin

wceolin

That was fixed: on_cancel={JS.patch(~p"/<url>")} is the default now: Liveview traffic over the wire - #7 by chrismccord

awerment

awerment

Glad to hear! :slight_smile:

Not sure if this is a bug - re-mounting the LiveView also loads the latest entries from the DB. That means, when using patch here instead of navigate you could get stale data displayed. Though that would mean another user or background process is editing records as well - at which point you probably want to use PubSub anyhow?

neurodynamic

neurodynamic

Ooh I never would have found that; thank you! That seems to have resolved it for me.

Do you think this is worth reporting as a bug, or are there reasons navigate might make sense as the default behavior for others?

Where Next?

Popular in Questions Top

hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a &gt; b) do {:ok, "a"} end if (a &lt; b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
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
New

Other popular topics Top

Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29703 241
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
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36432 110
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
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
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

We're in Beta

About us Mission Statement