Files
fizzy/app/javascript/controllers/form_controller.js
T
2025-09-29 19:00:17 +02:00

44 lines
788 B
JavaScript

import { Controller } from "@hotwired/stimulus"
import { debounce } from "helpers/timing_helpers";
export default class extends Controller {
static targets = [ "cancel" ]
static values = {
debounceTimeout: { type: Number, default: 300 }
}
initialize() {
this.debouncedSubmit = debounce(this.debouncedSubmit.bind(this), this.debounceTimeoutValue)
}
submit() {
this.element.requestSubmit()
}
debouncedSubmit(event) {
this.submit(event)
}
submitToTopTarget(event) {
this.element.setAttribute("data-turbo-frame", "_top")
this.submit()
}
reset() {
this.element.reset()
}
cancel() {
this.cancelTarget?.click()
}
preventAttachment(event) {
event.preventDefault()
}
select(event) {
event.target.select()
}
}