caspg

caspg

Hi everyone,

I recently implemented a real-time search feature in a Phoenix application using LiveView and Tailwind, and I wanted to share the code with the community.

The code includes an example of how to use LiveView to dynamically update the search results based on user input, as well as some optional TypeScript code to allow users to navigate the search results using the keyboard (up and down arrow keys).

You can check out a demo of the feature in action at travelermap.net (search bar is in top right corner), and I have to say, the results are super cool :sweat_smile:! The real-time updates are seamless and make the search experience much more intuitive.

:point_right: Here’s a link to the code on GitHub:

Let me know if you have any questions or feedback!

Showing Posts 1 to 10

f0rest8

f0rest8

This is really awesome, and love that you made it for parks! Loved flying in to look at the different parks and read about them. The search is great too :wink: Thanks for sharing! :orange_heart:

caspg

caspg OP

I’m glad you found it interesting :slight_smile: The flying on the map is handled purely by MapLibre lib. I only had to make it play nicely with LiveView :fire:

PJo336

PJo336

Thanks for sharing, always love checking out other liveview projects.

Random side question, how did you do your modals? I see you aren’t using the URL style like in the generators. Are you using a send_update or something?

Edited to add: i see the search modal is just JS, but to open like the wikipedia modal, is this similar?

caspg

caspg OP

Wikipedia modal is pure JS. I created this website as a static, non-live phoenix app. Now, I’m in the process of migrating to live views. But still, I think modals should be opened with JS commands to avoid round trips to the server.

maz

maz

Very nice! What mapping component are you using?

ghenry

ghenry

In a new Phoenix 1.7 app you get core_components.ex with a modal example it it. I’ve modified it into a TailwindUI modal:


    <!-- Logout confirmation modal -->
    <.modal
      id="confirm_logout"
      on_confirm={JS.navigate(~p"/logout")}
      on_cancel={JS.hide(to: "#confirm_logout")}
    >
      <:title>Logout</:title>
      Are you sure you?
      <:confirm>Logout</:confirm>
      <:cancel>Cancel</:cancel>
    </.modal>

No server side things at all. Check out 1.7 :slight_smile:

caspg

caspg OP

@ghenry I’m using 1.7 :slight_smile: I was just referencing the previous comment asking if I’m using send_update.

@maz I’m just using https://maplibre.org/projects/maplibre-gl-js/. The map is rendered as separate LiveView with sticky: true option so it’s not re-rendered between navigations.

maz

maz

Awesome chunk of code. Thanks.

mustela

mustela

Thanks for sharing it! I was looking for exactly this functionality. THANKS A LOT!

milangupta

milangupta

Really neat ! Thank you ..
I have been trying to figure out a fuzzier search than ilike .. try adding this .. helps with spelling mistakes etc.

    |> where(fragment("SIMILARITY(p.name, ?) > .30", ^search_query))
    |> order_by(fragment("LEVENSHTEIN(p.name, ?)", ^search_query))

Where Next? Top

Trending in Guides/Tuts Top

c4lliope
# ~/src/livebook/.iex.exs System.cmd("xdg-open", [ LivebookWeb.Endpoint.access_url() ] ) Because Livebook requires a unique passcode on ...
New

Other Trending Topics Top

GenericJam
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
JesseHerrick
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
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
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
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews