sergio_101

sergio_101

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!

Showing Posts 1 to 4

lucaong

lucaong

If you do not want to use LiveView, you can use the same pattern that you were using with Rails. I see nothing wrong with it in principles.

That said, you do not need to convert the whole app to LiveView in order to use it in one specific place.

sergio_101

sergio_101 OP

OH! Does LiveView seem like overkill or more work to solve the above problem? I read up a bit on liveview, and it seemed like a great way to handle such things. But i didn’t know I could use it on such a limited basis

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 OP

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!

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
Aludel - LLM Evaluation Workbench Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews