z7ealth

z7ealth

Hi everyone,

I’m currently working on two projects with Phoenix and LiveView, and I’m looking for tips or suggestions on improving the frontend side. I’ve managed to implement basic functionality using core_components and LiveView.JS, but I get stuck when I need something more advanced. For example, I’m unsure how to dynamically update select options based on previous selections (e.g., select country → select state → select city), handle actions involving multiple checkboxes, or implement table sorting.

I’m still new to this, and I know it might just be a skill gap, which is why I’m reaching out. I’d love to hear how Saint Jose disciples approach and solve these kinds of challenges.

For context, I have a background in Ember.js with EmberPaper and React with Ant Design.

Showing Posts 1 to 8

joddm

joddm

Would also appreciate this :slightly_smiling_face:

I’m more comfortable with the back-end, and a total noob on front-end stuff

D4no0

D4no0

If you work currently on a toy project my advice is to not use JS at all, do everything server-side.

The trend I see currently being pushed in liveview ecosystem is interaction with JS from liveview, in order to avoid server latency, which is not exactly what liveview was built for. The idea of liveview is to simplify web development by keeping the frontend interaction on the elixir side, instead of having both JS and backend code like in your classical 2 stack web app. There is obviously a price to pay for this abstraction and that is your UI becomes janky if your connection is unstable.

The JS interlop is an important hack to overcome liveview limitations (for example interaction with JS libraries like maplibre.js), however IMO it should be used only when all other options are exhausted, as the more JS you use, the exponentially less benefit you get from using liveview.

Pal

Pal

You couldn’t do better than starting with:

Aiken00

Aiken00

how about pragmatic studio?

ipnon

ipnon

The best way to learn is to hack on the coolest project you can think of. With frameworks like React you can footgun and spend months or even years studying how to do everything the right way without ever writing a real line of code, let alone actually taking a project from start to finish. You always learn so much more by making something real.

Let your experience guide you! For example, I needed to play an MP3 in a LiveView when a user clicks an icon yesterday. My first approach that I imagined used a React-style solution where I’d conditionally render audio tags based on if a certain file existed on another host … totally wrong. I read some docs, did some rubber ducking with an LLM, and found out you can solve this super easy with 2 HTML attributes and a few lines of JavaScript to interop with the Audio WebAPI.

~H"""
<div>
  <%= if @audio_url do %>
    <!-- Don't forget to include a unique `id` attribute or the hook will have undefined behavior! -->
    <div
      id="audio-button"
      data-audio-url={@audio_url}
      phx-hook="PlayAudio"
    >
      🎵 Play Audio
    </div>
  <% end %>
</div>
"""
let Hooks = {}

Hooks.PlayAudio = {
  mounted() {
    this.el.addEventListener("click", () => {
      const audioUrl = this.el.getAttribute("data-audio-url")
      if (audioUrl) {
        const audio = new Audio(audioUrl);
        audio.play().catch((error) => console.error("Audio playback failed:", error))
      }
    })
  }
}

let liveSocket = new LiveSocket("/live", Socket, { hooks: Hooks })
liveSocket.connect()

I probably never would have learned how to put all these little pieces together if I had stuck with book learning and watching lectures. Just jump right in to it. It’s more fun this way in my opinion. The Elixir community is very kind and helpful in my experience. It’s a great place to “learn in public.” You can always ask questions on this forum and post your projects when you’ve got a cool demo.

codeanpeace

codeanpeace

If you like a choose your own adventure approach, run and play around with open source sample apps like TodoTrek and LiveBeats to find the dynamic interactions that interest you. Then poke around their respective repos and use those interactions as a treasure map to direct your spelunking.

You can use the phx-change binding on the first input to send an event back to the socket that updates an assign used to populate the second input that depends on the first.

Here’s an example I made a while back that shows how to select organization → select user belonging to selected organization:

https://github.com/codeanpeace/live_cal/commit/300d7843a31f28a31678db0cf3dd81722656bec8

arcyfelix

arcyfelix

I can second that. Their courses are fantastic!

z7ealth

z7ealth OP

Thanks everyone!

Update: I switched to a NextJS frontend, after a week of using it, i went back to Phoenix :rofl:

Holy moly, now i just don’t mind if i spend 2 days on a select

:v

— 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
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
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
ryanwinchester
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted” Version...
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
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews