pejrich
I’m trying to use this WYSIWYG Markdown editor in my live view form https://github.com/sparksuite/simplemde-markdown-editor (Does anyone know which editor Elixir Forum uses, I want something like this).
Here’s my form
<div class="message_form" style="height: 100px;">
<%= form_for :message, "#", [phx_change: :typing, phx_submit: :save], fn f -> %>
<%= textarea f, :text, id: "wysiwyg", phx_hook: "messageTextarea" %>
<%= submit "Save" %>
<% end %>
</div>
Here’s my JS
Hooks.messageTextarea = {
mounted() {
new SimpleMDE({ element: document.getElementById("wysiwyg") });
},
updated() {
new SimpleMDE({ element: document.getElementById("wysiwyg") });
},
The editor appears when the page loads, but when the first character is typed, there is a reload, the editor appears again, but there’s no text in it. If I log the events, I seem to get a bunch of beforeUpdate and updated events firing. How can I keep my events, but stop it from reloading the text area on each character typed?
Trending in Questions
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
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
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
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
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
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
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
Other Trending Topics
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
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
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
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
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
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
LostKobrakai
You likely want to set the textarea to
phx-update="ignore"and not reinitialize SimpleMDE. Also instead ofdocument.getElementById("wysiwyg")you could just usethis.el.pejrich
Putting
phx_update: "ignore"on the textarea didn’t do anything. It did work if I putphx_update: "ignore"on the form itself. However then the form doesn’t reset after submitting.LostKobrakai
You can try putting the textarea in a wrapping element like a
divand only make this one bephx_update: "ignore".pejrich
If I do that, it still doesn’t reset the text area to blank after submitting. I don’t mind that, as long as I can trigger something after saving to clear the textarea.
LostKobrakai
Yeah, this is the place where you’ll notice the problem of having to places trying to be the source of truth. The only “trigger” your liveview will get it that the
updated()part of your hook is called.pejrich
Presumably after each “change” event is fired, LiveView does something and reloads the text area. Is there anyway to hook into that update and only update the
valueof the text area, instead of completely reloading the element?LostKobrakai
Nope, the server doesn’t send structured updates. It just sends optimized template diffs.
pejrich
I see. I guess I can either have the WYSIWYG editor, or the
user_is_typingindicator, but not both. Hmm. Maybe i can hack around it with some JS.pejrich
Is there a way to manually send a phx event from JS? If I put
phx-change="typing"on something, that doesn’t work if my JS lib replaces the element. Is there a way I can listen to changes via the 3rd party lib (I know how to do this part), and then trigger events to get sent via phx? Kinda like in channels.channel.push("typing")mindok
pushEventis what you are looking for I think - documented here: Phoenix.LiveView — Phoenix LiveView v1.2.5