1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-19 13:19:39 +02:00
Maybe/app/javascript/controllers/auto_submit_form_controller.js
Zach Gollwitzer f0c2d4ead0
Implement transaction filtering UI (#578)
* Rough sketch of implementation

* Consolidate auto submit controller

* Store ransack params in session

* Improve how summary is calculated for txns

* Implement filters UI
2024-03-28 13:23:54 -04:00

26 lines
700 B
JavaScript

import { Controller } from "@hotwired/stimulus";
export default class extends Controller {
// By default, auto-submit is "opt-in" to avoid unexpected behavior. Each `auto` target
// will trigger a form submission when the input event is triggered.
static targets = ["auto"];
connect() {
this.autoTargets.forEach((element) => {
element.addEventListener("input", this.handleInput);
});
}
disconnect() {
this.autoTargets.forEach((element) => {
element.removeEventListener("input", this.handleInput);
});
}
handleInput = () => {
clearTimeout(this.timeout);
this.timeout = setTimeout(() => {
this.element.requestSubmit();
}, 500);
};
}