x
1
2
3
<form data-controller="form" action="/slow_action" accept-charset="UTF-8" method="post"><input type="hidden" name="authenticity_token" value="f6D115mUdR5H6jWj_1rSupg6N2bFNUn8VCmIpeKd3E3BawAUfpueciRXKYPowMkuHlWScz4cT9gW228sfId__A" autocomplete="off" /> <input placeholder="Filter tasks.." autocomplete="off" class="input" data-action="form#submitLater" type="search" name="filter_tasks" id="filter_tasks" /></form>
1
2
3
<%= form_with url: main_app.slow_action_path, data: { controller: "form" } do |form| %> <%= form.search_field :filter_tasks, placeholder: "Filter tasks..", autocomplete: "off", class: "input", data: { action: "form#submitLater" } %><% end %>
CSS is not required or multiple files are needed, check the notes.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { Controller } from "@hotwired/stimulus"import debounce from "https://esm.sh/just-debounce-it@3.2.0?standalone"export default class extends Controller { static targets = [ "cancel" ] initialize() { this.submitLater = debounce(this.submit.bind(this), 500) } submit({ params: { submitter } }) { if (submitter) { this.element.requestSubmit(this.#find(submitter)) } else { this.element.requestSubmit() } } cancel() { this.cancelTarget?.click() } preventAttachment(event) { event.preventDefault() } #find(id) { return document.getElementById(id) || this.#notFound(id) } #notFound(id) { throw new Error(`Submitter with ID "${id}" not found`) }}
No notes provided.