Submitting form from the new combos

This commit is contained in:
Jorge Manrubia
2025-09-18 15:23:37 +02:00
parent 66b0a4f2e7
commit 408374ff33
4 changed files with 18 additions and 16 deletions
@@ -1,7 +1,7 @@
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
static targets = [ "label", "item" ]
static targets = [ "label", "item", "hiddenField" ]
static values = { selectPropertyName: { type: String, default: "aria-checked" } }
connect() {
@@ -16,8 +16,7 @@ export default class extends Controller {
}
get #selectedLabel() {
const label = this.#selectedItem.querySelector("[data-combobox-label]")
return label.dataset.comboboxLabel
return this.#selectedItem?.dataset?.comboboxLabel || ""
}
get #selectedItem() {
@@ -28,6 +27,7 @@ export default class extends Controller {
this.#clearSelection()
item.setAttribute(this.selectPropertyNameValue, "true")
this.labelTarget.textContent = this.#selectedLabel
this.hiddenFieldTarget.value = item.dataset.comboboxValue
}
#clearSelection() {