coen.bakker
I have story_cards that render a list of authors, among other things. Clicking an author should open a modal, via a function set_modal_data/1. This function needs the to be passed one author (not all authors).
Is there a way to pass the set_modal_click/1 function to the story_card function component call (e.g. <.story_card ... on_author_click={...}/>? Currently, I am using slots to be able assign the set_modal_click/1 to the phx-click that should open the modal.
# current solution
<.story_card
:for={story <- @stories}
story={story}
>
<:author let={author}>
<span
class="pub-cover-author-tag"
phx-click={set_modal_data(%{"id" => author.id, "modal" => "user"})}
>
<%= author.username %>
</span>
</:author>
</.story_card>
# hypothesized solution
<.story_card
:for={story <- @stories}
story={story}
let={author}
on_author_click={set_modal_data(%{"id" => author.id, "modal" => "user"})}
/>
Ty
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
I’m working on a small exercise involving update_in/3, and I came up with this solution:
data = %{
name: "Periodic Table",
category:...
New
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication):
toke...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #metaprogramming
- #hex










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
ken-kost
I know you’re not using Surface but perhaps this documentation could help you.
if you have
current_userstored in your socket, you could send it together with authorSomething like that perhaps, then you could check inside story card if the current user is the author or not and act accordingly.
Not sure if I’m being relevant.
coen.bakker
Rereading my post, I notice I should have explained it better.
There is a comprehension for authors inside the story_card function component:
for author <- @authors do .... One story_card shows a html-element with aphx-clickfor each author.So the comprehension giving the
authormap can be found here (made some adjustments for this post so might contain typo’s):sodapopcan
You should be able to pass it as a capture:
and then:
I may also be misunderstand what you’re after, though!
coen.bakker
Oh yes. I see what you mean. I haven’t thought of it that way yet.
The reason for my post was that I like to be able to see all my LiveView event calls from my LiveView modules.
So I try to prevent this:
Instead, I have been doing:
However, some components have bindings (e.g. phx-click) inside them that are inside a comprehension expression. For example:
I was wondering if I can pass that
JS.push("some_event", value: %{item: item})from the last example/code block to the<.some_component/>component from the render function of the LiveView module, somehow.Some like:
sodapopcan
That makes sense!
It should work with the capture:
(sorry I forgot the
@in my original example)Possibly you already got that but I wasn’t sure from your response
coen.bakker
Great. Love it.
Ty
coen.bakker
Just got back to my computer to implement it and I am getting an error saying:
I am not familiar with having to explicitly implement Jason.Encoder protocol for a struct I own (in this case User, which corresponds with the author variable from earlier). Is this error to be expected when implementing the solution you suggested, that you know? This might be a good opportunity for me to learn more about implementing the Jason.Encoder protocol, in that case.
edit:
This is the stack trace I am getting:
sodapopcan
Oh right, I was sort of afraid of that, lol. It’s just saying you can’t encode an Elixir struct into HTML which makes sense. I think you can just put
@derive Json.Encoderin your schema. The idea is that it’s telling it how to convert a schema into JSON. That should work (I’m not actually trying these things as I type them). You could also explicitly pass the artist attributes as in your original example:benwilson512
Be very careful with this. The user struct in this case is being sent to the JS front end unencrypted. I would strongly suggest pulling out specific keys that are relevant to the JS.
sodapopcan
Right, you’d need to make sure you have the redacted fields set. Thanks for chiming in, I did not think of that!