Skip to content

Instantly share code, notes, and snippets.

@NisTa24
Created June 1, 2025 13:53
Show Gist options
  • Save NisTa24/d5dc708ea18a73b40d2aa7fc2ebca301 to your computer and use it in GitHub Desktop.
Save NisTa24/d5dc708ea18a73b40d2aa7fc2ebca301 to your computer and use it in GitHub Desktop.
import { Controller } from "@hotwired/stimulus"
// Connects to data-controller="form"
export default class extends Controller {
static values = {
debounce: { type: Number, default: 500 }
}
connect() {
this.timeout = null;
}
disconnect() {
clearTimeout(this.timeout);
}
submit() {
clearTimeout(this.timeout);
this.timeout = setTimeout(() => this.element.requestSubmit(), this.debounceValue);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment