CherryPoppins

CherryPoppins

I have a toolbar component in my root.html.heex that is a form used to set a couple parameters on the user session when it is submitted to a controller and should redirect the user back to the same page with the same params. The page the user is coming from is a liveview using push_patch to update some filter params. So, the params are changing from what I have access to on conn at the time the toolbar is rendered with root.html.heex. I need to get the current url/params at the time the toolbar component form is submitted and include it as a hidden input in the form params. struggling to figure out how to accomplish this. this component has to be in the root as making it a live_component to handle this and putting it in all the liveviews is probably not going to be possible with the way the app is setup. we do have hotwired/stimulus as a dependency but if possible id like to avoid using it.

Showing Posts 1 to 6

KP123

KP123

You could push an event from the server and handle it in a Phoenix hook. Hooks are pretty much stimulus minus targets and outlets.

CherryPoppins

CherryPoppins OP

Don’t think you can use hooks in dead views

KP123

KP123

I’m under the impression that you want to update the dead part of a live page. Is that incorrect? What’s stopping you for manipulating the dead part dom with regular js from inside a hook?

CherryPoppins

CherryPoppins OP

that is correct. the reason i don’t want to use a hook in the LV to update the dead part is because its not scalable for this application. it would require the hook to be added to all the templates and for anywhere someone wants to use handle_params and push_patch they would also have to know they need to send the event to the client to update the dead part. its too many people and too many templates. i’d like for this to all remain in the dead component dropped into root so it works everywhere and there is only one place that controls it. right now i just have a script tag in the dead view heex that uses JS to add a submit event listener to the form and upon submitting the form adds the path from window.location to a hidden input then submits the form. but, for whatever reason that has a smell to me, so just wanted to see if there was a better way.

KP123

KP123

So:

  1. The data is only needed when you submit the form
  2. The form exists on a dead part of a live page
  3. The form is backed by a traditional controller

You could intercept the form submission using addEventListener, prevent the default submission, grab and parse the url as needed, ajax the form data to the backend then refresh the page on success

OR

You could use a mutation observer to figure out when the live view content changes, then update the hidden form field

OR

You could capture the refer header on form submit and navigate to there directly from the server.

CherryPoppins

CherryPoppins OP

The “referer” header idea I think is perfect! Going to try going down that route. 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
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
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

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
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews