From 8fced550d84bb6e2b72b061c6dd1e987801c7102 Mon Sep 17 00:00:00 2001 From: Adrien Maston Date: Tue, 3 Mar 2026 10:31:08 +0100 Subject: [PATCH] Refactor --- app/javascript/controllers/bar_controller.js | 6 ------ app/javascript/controllers/search_form_controller.js | 9 +++------ app/views/searches/_form.html.erb | 2 +- 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/app/javascript/controllers/bar_controller.js b/app/javascript/controllers/bar_controller.js index d3a861023..70f63990f 100644 --- a/app/javascript/controllers/bar_controller.js +++ b/app/javascript/controllers/bar_controller.js @@ -22,12 +22,6 @@ export default class extends Controller { this.#hideItem(this.searchTarget) } - clearInput(event) { - if (event.detail.isAlreadyEmpty) { - this.reset() - } - } - showModalAndSubmit(event) { this.showModal() this.formTarget.requestSubmit() diff --git a/app/javascript/controllers/search_form_controller.js b/app/javascript/controllers/search_form_controller.js index c4efceedc..d48741cd5 100644 --- a/app/javascript/controllers/search_form_controller.js +++ b/app/javascript/controllers/search_form_controller.js @@ -4,14 +4,11 @@ export default class extends Controller { static targets = ["searchInput"] clearInput() { - this.dispatch("clear", { detail: { isAlreadyEmpty: this.isEmpty } }) - if (!this.isEmpty) { + if (this.searchInputTarget.value) { this.searchInputTarget.value = "" this.searchInputTarget.focus() + } else { + this.dispatch("reset") } } - - get isEmpty() { - return !this.searchInputTarget.value - } } diff --git a/app/views/searches/_form.html.erb b/app/views/searches/_form.html.erb index e3e4e3ba5..88bcafee0 100644 --- a/app/views/searches/_form.html.erb +++ b/app/views/searches/_form.html.erb @@ -2,7 +2,7 @@ class: "search__form flex align-center justify-center gap-half", data: { controller: "search-form", - action: "search-form:clear->bar#clearInput", + action: "search-form:reset->bar#reset", bar_target: "form", turbo_frame: defined?(target_turbo_frame) ? target_turbo_frame : nil } do |form| %> <%= form.label :q, "Search Fizzy", class: "font-weight-black txt-nowrap" %>