mirror of
https://github.com/we-promise/sure.git
synced 2026-04-10 15:54:48 +00:00
22 lines
626 B
JavaScript
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()
|
|
}
|
|
}
|
|
}
|