Skip to content

Commit

Permalink
fixed prevent request in debounce stimulus controller
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegPhenomenon committed Sep 6, 2023
1 parent 61ead60 commit be70fd1
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions app/javascript/controllers/behaviour/debounce_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,22 @@ import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
static targets = ["form"]

initialize() {
this.timeout = null;
this.initialLoad = true;
}


search(event) {
event.preventDefault();
if (this.initialLoad) {
this.initialLoad = false;
return;
}

clearTimeout(this.timeout)
clearTimeout(this.timeout);
this.timeout = setTimeout(() => {
this.formTarget.requestSubmit()
}, 300)
this.formTarget.requestSubmit();
}, 500);
}

disconnect() {
Expand Down

0 comments on commit be70fd1

Please sign in to comment.