mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-19 21:29:38 +02:00
30 lines
689 B
JavaScript
30 lines
689 B
JavaScript
|
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();
|
||
|
}
|
||
|
}
|