Created
June 1, 2025 13:53
-
-
Save NisTa24/d5dc708ea18a73b40d2aa7fc2ebca301 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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