wktdev
Phoenix 1.7 generator comes with a modal in “CoreComponents”.
The instructions do not explain how to toggle it.
The base syntax is:
<.modal
id="user-modal"
show >
The show attribute is what triggers the popup.
In JavaScript ,to trigger a modal you typically have a boolean to toggle the “show” attribute value. In Elixir I have no idea how to do that nor do I know if that is the approach that is expected of the developer to make it work.
The documentation is here:
<.modal id="confirm-modal">
Are you sure?
<:confirm>OK</:confirm>
<:cancel>Cancel</:cancel>
</.modal>
JS commands may be passed to the `:on_cancel` and `on_confirm` attributes
for the caller to react to each button press, for example:
<.modal id="confirm" on_confirm={JS.push("delete")} on_cancel={JS.navigate(~p"/posts")}>
Are you sure you?
<:confirm>OK</:confirm>
<:cancel>Cancel</:cancel>
</.modal>
The example does not explicitly show the show attribute, In the working example below from the phoenix generator, it is used.
<.modal
:if={@live_action in [:new, :edit]}
id="user-modal"
show
on_cancel={JS.navigate(~p"/users")}
>
<.live_component
module={AppxWeb.UserLive.FormComponent}
id={@user.id || :new}
title={@page_title}
action={@live_action}
user={@user}
patch={~p"/users"}
/>
</.modal>
Trending in Questions
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
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
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
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
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
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
I’m trying to set up Emacs with elixir-ls via lsp-mode and credo via Flycheck. This should mostly be preconfigured as Flycheck picks up c...
New
Other Trending Topics
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 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
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #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
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #ai
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 9- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
BradS2S
Bind the show attribute to a flag, ‘show_modal’
Then you can use a LiveView
handle_eventfunction that responds to aphx-updateevent, and updates a booleanshow_modalflag.You can set the default value if the show_modal flag when you mount
wktdev
I have no idea what a “flag” is.
When I search I get this:
EDIT:
I found this:
Feature flags, or feature toggles, are boolean values associated to a name . They should be used to control whether some application feature is enabled or disabled, and they are meant to be modified at runtime while an application is running. This is usually done by the people who control the application.
BradS2S
Usually it just means a Boolean variable. That’s how I use it. So wax on, wax off kind of deal
wktdev
Do you have a remedial example?
Every time I search for any of this stuff I get a giant jungle of text and nothing is clear and simple.
I searched for an example and I got some persons entire repository:
https://github.com/tompave/fun_with_flags
wktdev
How do I assign the event handler to the modal so it works?
edit, ignore comment above:
What I meant to say is, after I attached the event handler to a button, how do I bind all this to the modal?
I understand how to use assigns to set variables. The main problem I am having is I don’t know how to toggle the state of the actual modal.
wktdev
For anyone asking the same question it’s two lines of code and requires JavaScript. I spent a day and a half going in circles over this nonsense. It has nothing to do with the show command. The show/hide feature pertains to the ID assignment and that it needs the JS module.
bemesa21
I saw that you solved your problem, but I was already writing an answer for you. I’ll leave it here in case this example works for someone else.
A function
show_modal/2is also defined inCoreComponents, the only thing you need to pass to this function is theidof your modal. In this function, JS commands are used to display the modal and apply some transitions to it.So you just need to define the id of your modal:
and call that function:
codeanpeace
I totally understand it can be frustrating and I know it’s not likely your intention, but let’s not take it out on the project and its contributors. What might seem like “nonsense” when you’re frustrated usually begins to make a lot of sense with a little bit of curiosity, patience, and experience. For example…
… following the show attribute could have gotten you to those two lines of code much sooner. If you look at the function that defines the modal in the
CoreComponentsmodule, you’ll see the how the booleanshowattribute acts as a flag for theshow_modal/1function that takes an@idas an argument and wraps thePhoenix.LiveView.JS.show/2function among other JS commands.soyjeansoy
Massive thank youuuuu!!! the
show_modalfunction was already aliased!The reason for that is: I looked at
lib/your_app_web/your_app_web.ex,Took me lots of hours why
JS.show_modalis undefined on the page