sergio_101

sergio_101

Best practices for manipulating the DOM

We have a simple case where a form has two dropdowns. The options in the second rely on the choice of the first.

In rails, our go-to pattern for this was as follows:

  • Create the template to render whatever the default state of the dropdowns is.
  • Create an action that returns just the options tags for the submitted choice.
  • Using JS, when the first selection box is changed, make an ajax call to that new action. On response, swap out the old DOM element containing the old options with the new options.

At first, I thought LiveView was the go to on this, but after looking at LiveView, it seems like the entirety of the app needs to be written as a LiveView app. This is not, and it’s already pretty massive. Too massive to make the adjustment.

Then, I thought Channels might be the answer, but it looks like channels is a way to talk server → client.

So, how are people doing this daily in the Phoenix world?

Thanks!

Most Liked

lucaong

lucaong

LiveView is definitely a good way to solve your problem. The docs even list it as one of the common use-cases:

Handling of user interaction and inputs, buttons, and forms - such as input validation, dynamic forms, autocomplete, etc;

That said, it’s also perfectly fine to use plain JS for something like this. I’d say it’s up to you, maybe if populating this particular select box is your only need, and you feel more comfortable with plain JS, it might be overkill to introduce LiveView. But if you think it might turn out to be useful in other cases too, this could be an opportunity to start to gradually adopt it.

sergio_101

sergio_101

thanks so much for your input. This phase has some serious deadline issues, so I will probably use JS.. but Phase II is a little more open, so I will figure out how to do this.

Thanks!

Where Next?

Popular in Questions Top

_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
JulienCorb
I am trying to implement my new.html.eex file to create new posts on my website. new.html.eex: <h1>Create Post</h1> <%= ...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
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
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
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
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
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
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New

Other popular topics Top

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
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
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
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
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
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36128 110
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
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

We're in Beta

About us Mission Statement