mirror of
https://github.com/we-promise/sure.git
synced 2026-04-12 08:37:22 +00:00
Feat transactions search (#532)
* gem: Add ransack gem * feat: Implement transactions search
This commit is contained in:
29
app/javascript/controllers/transactions_search_controller.js
Normal file
29
app/javascript/controllers/transactions_search_controller.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import { Controller } from "@hotwired/stimulus"
|
||||
|
||||
export default class extends Controller {
|
||||
static targets = ["search", "date"]
|
||||
|
||||
connect() {
|
||||
this.timeout = null
|
||||
}
|
||||
|
||||
search() {
|
||||
clearTimeout(this.timeout);
|
||||
this.timeout = setTimeout(() => {
|
||||
this.submitForm();
|
||||
}, 300); // Debounce time in milliseconds
|
||||
}
|
||||
|
||||
submitForm() {
|
||||
const formData = new FormData(this.searchTarget.form);
|
||||
const searchParams = new URLSearchParams(formData).toString();
|
||||
const newUrl = `${window.location.pathname}?${searchParams}`;
|
||||
|
||||
history.pushState({}, '', newUrl);
|
||||
this.searchTarget.form.requestSubmit();
|
||||
}
|
||||
|
||||
afterSubmit() {
|
||||
this.searchTarget.focus();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user