Use datalist as a poor man's autocomplete for now

This commit is contained in:
Jason Zimdars
2024-08-05 17:51:18 -05:00
parent 177174ab77
commit 056a3c3062
3 changed files with 9 additions and 3 deletions
+1 -1
View File
@@ -11,7 +11,7 @@ class CategoriesController < ApplicationController
end
def create
@category = Category.new(category_params)
@category = Category.find_or_create_by(category_params)
@category.save
@category.splats << @splat
+7 -1
View File
@@ -1,6 +1,12 @@
<turbo-frame id="new_catgory">
<%= form_with model: [@splat, @category], data: { turbo_frame: "_top" } do |form| %>
<%= form.text_field :title, class: "input borderless", autofocus: "on" %>
<%= form.text_field :title, class: "input borderless", autofocus: "on", list: "categories-list" %>
<%= form.submit "Create Category", hidden: true %>
<datalist id="categories-list">
<%= Category.all.each do | category | %>
<option value="<%= category.title %>"></option>
<% end %>
</datalist>
<% end %>
</turbo-frame>
+1 -1
View File
@@ -75,7 +75,7 @@
<%= link_to splat, class: "splat__title-link flex align-center gap flex-item-grow" do %>
<strong><%= splat.title %></strong>
<% end %>
<small class="flex align-center gap flex-item-shrink">
<small class="flex align-center gap flex-item-no-shrink">
<% splat.categories.each do |category| %>
<%= link_to "# #{ category.title }", splats_path(category_id: category.id) %>
<% end %>