dalerka
I’m trygint to get Awesomplete working to add multiple tags to a post.
However following instructions doesn’t do anything, i.e.:
- I have a working app with Posts and Tags as liveview generated models.
- My Post’s live
form_component.exlooks like:
<%= f = form_for @changeset, "#",
id: "post-form",
phx_target: @myself,
phx_change: "validate",
phx_submit: "save" %>
<%= label f, "Post title" %>
<%= text_input f, :title %>
<%= error_tag f, :title %>
## Tag input(Awesomplete multi-select)
## @tags = " " - this is set in the form_component.ex/apply_action(socket, :new, _params)
## @tag_names = "tagone, tagtwo, tagthree ..."
<div class="form-group">
<%= label f, :tags, class: "form-label" %>
<%= text_input f, :tags, value: @tags, "data-list": @tag_names, "data-multiple": true %>
<%= error_tag f, :tags %>
</div>
<%= submit "Save", phx_disable_with: "Saving..." %>
</form>
## Awesomplete multi-select script:
<script >
new Awesomplete('input[data-multiple]', {
filter: function(text, input) {
return Awesomplete.FILTER_CONTAINS(text, input.match(/[^,]*$/)[0]);
},
item: function(text, input) {
return Awesomplete.ITEM(text, input.match(/[^,]*$/)[0]);
},
replace: function(text) {
var before = this.input.value.match(/^.+,\s*|/)[0];
this.input.value = before + text + ", ";
}
});
</script>
Unfortunately, typing in the Tag input doesn’t display any auto-suggest with tags.
Anyone has ideas on how to get auto-suggest working without Liveview-specific client-server overhead?
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
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
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
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
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
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
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
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
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
Exadra37
Javascript interop in LiveView is done via Hooks, see the official docs for more details:
dalerka
I did look into those docs, but still couldn’t figure the way to make it work with Awesomplete.
Can you point to some relevant example code?
Exadra37
The docs I linked have 2 code examples, one for a Phone number input and another for Infinit Scroll. Just adapt them to your use case.
So you need to do on the Phoenix Hook what you have inside
<script>...</script>.dalerka
That didn’t work. '(
I updated my
form_componentas:and moved the JS code to
app.js:However nothing happens (no auto-suggest, no errors on client/server), except (as before) the liveview gets triggered when typing in the Tags input field.
What am I missing here?
LostKobrakai
Liveview does update your input tag each time you change the value. Try setting it to
phx-update="ignore".Also instead of
'input[data-multiple]'you should attach tothis.el. Given that the liveview DOM can change partially you should attach js functionality on a per element basis not globally. You can’t just once apply awesomplete to all your input, but you need to attach it to each input when it comes up and likely also destroy the instance when the input it removed from the page.dalerka
Thanks for pointers! But the problem persists, i.e. I see no auto-suggestions.
I changed the relevant line to
Also I don’t quite understand why on first page/form load the generated markup is following:
and after typing a single letter the wrapping
<div class="awesomplete">andul, spanvanish leaving only:What am I doing wrong?
sfusato
What happens is that once you start typing, LiveView will kick in and any markup added there by the JS library will vanish on re-renders.
Surround your input tag in a div with
phx-update="ignore"as suggested above. Adding this on the input itself doesn’t help in this case, since Awesomeplete initializes in an html node that is a sibling to the input.dalerka
Already tried that too. But weirdly, looks like Liveview doesn’t respect that.
I still see the
<div class="awesomplete"> et al.being wiped out.sfusato
Make sure you are also adding an ID to the div with
phx-update="ignore".dalerka
Ah, thank you, missed this one and it did the trick!
So, the Awesomplete library is working as expected now.