Files
sure/app/javascript/controllers/form_dropdown_controller.js
2026-04-08 21:05:58 +02:00

22 lines
626 B
JavaScript

import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
static targets = ["input"]
onSelect(event) {
this.inputTarget.value = event.detail.value
const inputEvent = new Event("input", { bubbles: true })
this.inputTarget.dispatchEvent(inputEvent)
const changeEvent = new Event("change", { bubbles: true })
this.inputTarget.dispatchEvent(changeEvent)
const form = this.element.closest("form")
const controllers = (form?.dataset.controller || "").split(/\s+/)
if (form && controllers.includes("auto-submit-form")) {
form.requestSubmit()
}
}
}