pedromvieira
LiveView external JS after socket mounted?
What’s the best approach to allow an external javascript library in LiveView after initial mount?
Currently it only works on first HTTP mount. And after any socket update, it’s stop.
The idea it’s to enable side menu or dropdown features like those in Flowbite.
Currently our side menu is a Phoenix.Component with a child Phoenix.Component per section.
We tried phx-update="ignore".
DROPDOWN
For dropdown, we did via phx-hook and it’s working.
function changeDom(obj) {
let dropdownId = obj.getAttribute("data-dropdown-toggle");
let dropdownObj = document.getElementById(dropdownId);
let options = {
placement: "bottom",
onHide: () => {
// console.log("dropdown has been hidden");
},
onShow: () => {
// console.log("dropdown has been shown");
},
};
let newDropdown = new Dropdown(dropdownObj, obj, options);
}
const navDropdown = {
mounted() {
let obj = this.el;
changeDom(obj);
},
updated() {
let obj = this.el;
changeDom(obj);
},
destroyed() {},
};
export default navDropdown;
SIDE MENU
For side menu dropdown, we did via phx-hook and it’s working.
HEEX
<ComponentsCompany.side_menu
locale={@locale}
token={@token}
socket={@socket}
section="users"
section_item="users-profile"
/>
<button
id="myId"
...
phx-hook="sidemenu"
...
</button>
SELECT
For multiple select, we did via phx-hook and it’s working.
HEEX
<%= select(f, :data_gender, Locale.choose_gender(@locale),
value: CommonUI.data(@changeset, [:data, "gender"]),
name: "user[data][gender]",
class: "form-live-select-input",
"phx-hook": "select",
autocomplete: "new-gender"
) %>
HOOK
const slimSelect = {
mounted() {
let opts = finalOpts(this);
new SlimSelect(opts);
},
updated() {
let opts = finalOpts(this);
new SlimSelect(opts);
},
destroyed() {},
};
export default slimSelect;
First Post!
cmo
Last Post!
cmo
Popular in Questions
Hi!
In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir?
Searched the docs for ip address and the web, no good results.
Thanks!
New
Hello, how can I check the Phoenix version ?
Thanks !
New
Hi there,
I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
Hey,
Just curious what are the main benefits of Elixir compared to Clojure?
When is Elixir more useful than Clojure and vice versa?
Th...
New
Other popular topics
Update:
How to use the Blogs & Podcasts section
You can post links to your blog posts or podcasts either in one of the Official Blog...
New
Hi!
In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir?
Searched the docs for ip address and the web, no good results.
Thanks!
New
Hello, how can I check the Phoenix version ?
Thanks !
New
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
New
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar.
I p...
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
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









