josefrichter

josefrichter

LiveView: submit form and update URL

Hi, what is the correct way to update URL params upon submitting a form, please?

I have a search input field with standard submit button, that has phx-submit binding. But I want pagination on the search results, too.

Generally one would probably go to /users/search-results and then have prev/next live_patch links there.

But what if I wanted to stay on the same page, and just update params like /users?search=john&page=1&per_page=10? Therefore the whole thing working more like a text filter?

Basically, how do I get the value from form textfield into URL, please?

Thank you

Marked As Solved

cmo

cmo

In handle_event call push_patch(socket, to: Routes.live_path(socket, Something, %{search: "John", page: 1, per_page: 10}). Then you do the validation and assigning of params in handle_params.

Also Liked

cmo

cmo

Another post on this topic: LiveView push_patch append to params - #8 by josevalim

And yes to the above question.

Last Post!

josefrichter

josefrichter

ok, thank you!

Where Next?

Popular in Questions Top

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
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
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
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
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

Other popular topics Top

Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
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
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
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
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

We're in Beta

About us Mission Statement